Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

The classic question is whether to store images in a database or on the file system. In my case I feel it is probably best to store it on the file system.

However the specific order of the albums and images is very important. Originally I thought that I could do this by displaying images in the order of their last modified date and then artificially change that value to modify the order. However that method is flawed as adding new images to an album will reorder all the images as the modified time is changed unwillingly.

Can anyone give me advice on how I can keep track of the order without using a database?

(Not 100% sure if this question belongs here or maybe on stackoverflow, but I'm taking my chances and if I'm wrong feel free to correct it.)

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

You can use simple text file to simulate real database. If folder = album, then store order of images in text file in each folder (same file name, for example: order.txt.db).

Possible file format:

  • single line of text that you need to parse after reading from file (for example: file1.jpg|file2.jpg|file5.jpg|file3.jpg) -- it is easy to parse if you select right delimiter that is not part of the actual file name;

  • one line per file (each file on new line) -- maybe even better, as new line is definitely unique delimiter that will not be part of the file name;

  • scripting language-specific format (for example: serialized array for PHP -- using serialize() function) -- can easily be un-serialized and ready to use with no additional parsing (as un-serializing routine will do all parsing job for you).


If your hosting plan does not allow/support MySQL or similar database engine .. then it may support SQLite -- it is fast and one database = one file which can be stored as any other file on your site (just need read-write access).


Another approach would be renaming file names to include sorting order number (e.g. 001-file1.jpg, 002-file5.jpg etc), but this is more complicated to manage (kind of similar problems to using file modification time).

share|improve this answer
    
Technically the naming solution is better than the modification time one. For the latter, adding a file will change the modifcation time of the album (the folder it is in) and hence that order will be unwillingly changed each time a image is added. While for the former method, new images can simply be displayed at the end of the order until they are given a specific place. –  Chaim Chaikin Aug 20 '11 at 20:03
add comment

A programming option would be to store the image order in the EXIF data of the jpg files.

There's a UserComment or ImageDescription property you could use - assuming that these weren't already used in the image of course.

This will be slower than using an external file/database or changing the names or timestamps of the files, but it is self contained.

share|improve this answer
    
Too bad that this approach require reading the EXIF data from each file in order to detect correct sorting order. Compared to other possible approaches this seems to generate quite a lot of overhead (disk activity in particular, if there are a lot of files/albums). But nevertheless it's an interesting idea. –  LazyOne Aug 20 '11 at 22:04
    
@LazyOne - I didn't claim it would be faster - it's just a solution that doesn't require an external file/database or changing the names or timestamps of the files. –  ChrisF Aug 21 '11 at 13:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.