Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are unique IDs (GUID's) good for website image filenames?

Tags:

php

guid

image

seo

I'm having a debate with a fellow programmer (PHP) and we both disagree when it comes to GUIDs. Assuming that information about each image is being stored in a DB and has its own primary key (int).

What reasons could there be for using a unique ID for the image filename, beyond not having to worry about duplicate filenames?

I don't want to disregard his methodology, but it doesn't sit well with me either.

Thanks! Ben

Update: Having heard many +1's for GUIDs, how might SEO be affected by "randomly" generated image filenames? (Thanks Sukumar)

like image 709
Ben Avatar asked Aug 08 '11 08:08

Ben


2 Answers

What reasons could there be for using a unique ID for the image filename, beyond not having to worry about duplicate filenames?

Using an auto-increment primary key for a file name would make it possible to guess other images' URL's, which may be something you do not want - depending on how your system works, users could, for example, gain access to images that aren't intended for publication (yet).

I think using unique IDs is quite a good idea.

like image 181
Pekka Avatar answered Sep 22 '22 13:09

Pekka


Advantages of using GUID for filenames

  • Get unpredictable filenames.
  • Names that scale (don't need to worry about renaming files when DB is sharded).

Disadvantages of using GUID for filenames

  • Have to store additional data in the database.

Advantages of using DB primary key for filenames

  • Saves storage by reducing the need for an additional column.

Disadvantages of using DB primary key for filenames

  • Creates predictable filenames allowing users to "guess".

Summary: It is a trade-off you need to consider based on your requirements. More preference seems to be given to choosing GUIDs though.

like image 37
2 revs Avatar answered Sep 19 '22 13:09

2 revs