What is the most efficient way to store and access

2019-09-03 10:54发布

问题:

I am working on a project which has to store tens and thousands of images on a server and let the users access them. I need the most efficient method to store these images and to retrieve them. Also, I need information about which technology I should opt. I haven't started the project yet. So, I am thinking between PHP w/ CodeIgniter and Ruby on Rails.

The site hosts many images that are uploaded only by the Authors of the content, and not by the users.

回答1:

When you store images, it is beneficial to generate a checksums for them so you can check if images are duplicated and store only one instance.

Organization of folders is important as file system seeks images just like a relative database and many images in one folder would be a problem. When you have already implemented checksumming, you could easily create a directory structure from checksum, for example first two characters of MD5 would be 1st level of subfolders and two next characters would be a second level. The remaining characters would be the image file itself. If you want to allow duplicates, after checksum you can add a suffix for image name.

Regarding storage - you should have a separate static content server with fast and specialized web server like nginx or lighttpd to forget about performance issues. HDD should set up as a a RAID array.

EDIT: For your web project requirements, just store information about images in the database, used framework is not relevant to image storage itself.



回答2:

If you use PHP, you could always use some of the software available for image storage and manipulation, like Gallery, or phpThumb, or at least, have a look at their code so you don't have to reinvent the wheel. Having said that, I am sure there must exist similar libraries for ruby.



回答3:

Look a bit around, this is very common question. But these links might help you

  • PHP: accepting user uploads best practices!
  • Rails: http://www.therailsway.com/2009/3/16/storing-your-files

You may want to research more

Edit#1: One suggestion, just don't store your images in database.