存储上传图像的最佳方法 [英] Best approach for storing uploaded image
问题描述
将图像作为blob存储在数据库中vs仅存储数据库中的文件名有什么优点和缺点。
我使用PHP(CodeIgniter)和MySQL。
我知道这个问题是主观的,但客户问我这个问题,我不能给一个好的回答。
我通常会说:
- 更难以扩展:
- 具有大小为几GB的DB,因为图像将使许多事情(例如备份)
> - 从文件系统提供图片是网络服务器做的很好
- ,它允许一个人做一些任务
- 我想,如果需要,使用纯旧文件也会使你想使用某种类型的日子更容易一些的CDN
这意味着我几乎总是在文件系统中存储图像/文件,并且只在数据库中存储文件的名称(以及可能的大小和内容类型 - 始终有用)。
想想,这个问题可能是重复的...哦,是的,它实际上是;请至少查看这些问题和答案:
What are the advantages and disadvantages of storing an image as a blob in the database vs storing just the file name in the database.
I'm using PHP(CodeIgniter) with MySQL.
I know this question is subjective but a client asked me this question and I couldn't give a good answer.
I'd generally say that :
- database is harder to scale :
- having a DB that has a size of several GB because of images will make many things (backup, for example) harder.
- do you want to put more load on your DB servers, to serve... files ?
- serving images from the filesystem is something that webservers do well
- and it allows one to do some tasks (like generating thumbnails, for example) without involving the DB server
- I suppose, if needed, that using plain old files will also make things easier the day you want to use some kind of CDN
Which means I would almost always store images / files in the filesystem, and only store the file's name (and, possibly, size and content-type -- that can always be useful) in the database.
Thinking about it, that question is probably a duplicate... Oh, yes, it actually is ; see at least those questions+answers :
- Store images(jpg,gif,png) in filesystem or DB?
- Storing Images : DB or File System -
- Storing Images in DB - Yea or Nay?
- store image in database or in a system file ?
这篇关于存储上传图像的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!