PHP图片上传方法
我正在开发一个 PHP 网站,但我很难选择存储上传文件的最佳方法。
目前我正在考虑将图像作为 BLOB 存储在 MySQL 数据库中,但我也被告知存储图像的文件名就足够了。
I am developing a PHP website and I am having difficulty choosing the best method for storing uploaded files.
At the moment I am considering storing the image as a BLOB in the MySQL database but I have also been told that storing the file name of the image would be enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两者都有优点和缺点,我个人喜欢将图像存储在数据库之外,并在数据库中使用 varchar 引用文件。
如果您想将它们存储为 blob,那么这篇文章是一篇非常平衡的文章。
http://www.phpro.org/tutorials/Storing -MySQL-with-PHP.html 中的图像
There are advantages and disadvantages to both, personally i like to store the images outside of the db and reference the file using a varchar in the db.
If you want to go down the route of storing them as a blob, then this article is a nicely balanced one.
http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html
在我看来,仅将文件名存储在数据库中是快速且丰富的技术。您应该将文件保存在任何其他目录中。当您必须检索上传的文件时,您只需将其与存储的名称进行比较即可。如果您要存储多种类型的文件,那么将它们存储在不同的目录中始终是一个好方法。因此,在我看来,将文件名存储在数据库和其他地方的文件中是快速且良好的技术
In my opinion storing the file names only in database is fast and rich technique. you should save the files in any other directory. When you have to retrieve, your uploaded file you just need to compare it with stored name. If you are storing multiple types of files, so its always a good technique to store them in different directories. So storing the file name in database and file elsewhere is fast and good technique in my opinion