开发者

Read image from folder using php or database

Is it better to read and list images directly from file syst开发者_如何转开发em using simple php, or is it better to store image meta info and filename in the database and access the images by doing a mysql select. What are the pros and cons of both solutions.


Listing files on a file system is probably the easiest way to accomplish what you trying to do but it's going to be very slow if you are trying to cycle through several thousand directories/files on a networked file system (NFS, CIFS, GlusterFS, etc).

Storing files in a database will create a much more overhead since you are now involving an external application to store information. You have to remember that every time you are using a database you are also using network I/O, authentication mechanism, query parser, etc. At the same time all of this overhead might provide for a faster response then using a networked file system.

To conclude - everything depends on amount of files you are working with and underlying infrastructure. Two major things to look out for are going to be disk I/O and network I/O.


I would do the following:

  1. Upload all the images in one directory
  2. Store references to those images that are tied to the uploader's User ID
  3. Then just select the image URLs that are tied to that ID, and output them however necessary.


People find it easier to store their files within folders and parse that folder with php. If you go the database method the database eventually gets larger and larger and larger.

I can see it becoming personal preference, but I personally have gone with parsing folders for images rather than storing it within a database.

Depends on the scale of what you are doing.


This is what I would be doing.

  1. Store the file metadata in the database. You can store quite a bit of information about this image this way.
  2. Store the image file on a distributed storage system like Amazon S3. Store the path in your metadata. Replication is part of the system. And it easily integrates with Cloudfront CDN.
  3. Distribute the the images through Amazon Cloudfront CDN.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜