Are unique identifiers (GUIDs) useful for site image file names?

I have a debate with another programmer (PHP), and we both disagree when it comes to GUIDs. Assuming that information about each image is stored in the database and has its own primary key (int).

What could be the reason for using a unique identifier for the image file name, except that you do not need to worry about duplicate file names?

I do not want to ignore his methodology, but he does not suit me either.

Thanks! Ben

Update: After hearing a lot of +1 for GUIDs, how will SEO affect "randomly" generated image file names? (Thanks to Sukumar)

+8
php guid seo image
source share
4 answers

What could be the reason for using a unique identifier for the image file name, except that you do not need to worry about duplicate file names?

Using a primary key with an automatic increment for the file name will allow you to guess the URLs of other images, which may be something you donโ€™t want - depending on how your system works, users can, for example, access images that not intended for publication (yet).

I think using unique identifiers is a good idea.

+12
source share

Benefits of using a GUID for file names

  • Get unpredictable file names.
  • Names that scale (you donโ€™t need to worry about renaming files when debugging a database).

Disadvantages of using a GUID for file names

  • It is necessary to store additional data in the database.

Benefits of using a primary database key for file names

  • Saves memory by reducing the need for an extra column.

Disadvantages of using a primary database key for file names

  • Creates predictable file names that allow users to "guess."

Summary This is a compromise that needs to be considered based on your requirements. However, preference is given to choosing a GUID.

+4
source share

UUID great when you need to have unpredictable file names, so no one can download all files without the correct URLs.

+1
source share

If you store it in a database using a primary key, I would suggest using it as a unique identifier (and thus the file name). It does not make sense to have two unique columns in the database identifying one resource. By the way, I would not use the auto-increment field for this primary key. It is easy to guess other image identifiers that may be undesirable.

The choice between the two is a matter of taste, which I think. We use both. File names are what are mostly used, but then you must have permission to view the file. We also use a unique identifier, but this is necessary to prevent verification of rights and provide someone with the opportunity to share images with non-users.

0
source share

All Articles