Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a website that allows user to upload and display images.

Currently, I am not using a database to track these user images. A folder having the user id as the folder name is created for each user and under each folder, the image files are labelled numerically with filenames ranging from 01.jpg to 20.jpg. Up to 20 such images can be displayed on each user page.

I am using javascript to hide these images in case of any of them is absent. I have seen many websites having user images with unique random filenames and possibly tracking these files with a database

Since obscurity is not something that I need for these web accessible images, is there any reason why I should track them with a DB?

I am not sure if a reduction of 404 errors is a good enough reason to justify the added complexity of maintaining a database or can anyone enlighten me?

share|improve this question
I don't see how a database has anything to do with 404 errors? The two are unrelated. Also, a database itself does not necessarily introduce any more obscurity. – w3dk Sep 19 '12 at 11:42
up vote 4 down vote accepted

If your system works as it is now, I don't think it will be a good idea to move on. Since you will need lots of migration, script update, etc ..

From my point of view, the only reason you should store an image in DB (store only the path, not as binary) is to easily retrieve them. That's all. If you write your code depending on id as image filename, that's fine. On an other side, you're saving query from the DB. You don't have to query the DB to retrieve filename.

From a SEO point of view, it will be better if the image isn't only an id. Google (or what ever search engine) won't really know what 18.jpg is. It will have a better idea if you use an alt attribute, of course. But it will be better for him if you use slug instead and id (to retrieve them easily), like user-avatar-question-overflow-18.jpg. But this can also be done without a DB.

share|improve this answer
+1 Commercially, if you have a working system and don't require any additional functionality then don't "upgrade". If you aren't storing any additional 'data' (tracking stats, image data, etc.) then is there any need at all for a database? The filesystem is the database. (Although on a system where you have multiple users uploading content, then it's hard to imagine that you don't require more 'data' to be stored, in which case a database would probably be mandatory.) - basically what j0k says. :) – w3dk Sep 19 '12 at 12:10
Can you clarify your last point? Does adding a constant prefix to 20 images help improve SEO? I thought it is useful if only the description is unique for each file. But that would require DB. I haven't launch the site yet. So would you still recommend keeping same? @w3d is right. I do have database, it is just whether I want to allocate resources for this purpose. Thanks and +1 :) – Question Overflow Sep 19 '12 at 13:54
@QuestionOverflow I'm not a seo expert about image indexing. But I'm sure that Google will preferer user-avatar-question-overflow-18.jpg over 18.jpg. And if you can't have a different slug for each image, I think it's still a plus value to have one. – j0k Sep 19 '12 at 14:32

Your Answer


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.