views:

18

answers:

2

I am designing a website which will involve too many photos.

There are two modules Restaurants and Dishes. which is the best way to create the directory strcuture ?

images/Restaurants/ID images/Dishes/ID

am using the following to create the filename

function imgName($imgExtension)
  {
      return time() . substr(md5(microtime()), 0, 12) . ".".$imgExtension;
  }

ii want two different sized thumbnails. which is the best way to name the thumbnails ?

since the db will hold only the main pictures filename with extension.

+1  A: 

I wouldn't worry too much about the directory structure, what you have seems good, even better might be to use S3 buckets.

As for the filename part, I've found the simplest way is to prepend thumb_ to the thumb filename. So: somefilename.jpg -> thumb_somefilename.jpg

This way you can store somefilename.jpg in the database and simply add the extra part to the front when you want the thumb.

thenduks
+1  A: 

Is there any reason for randomising the filenames like this? It's my personal opinion that you shouldn't be giving them random names in the first place, they should relate to what's actually in the picture - simply because it's nicer for users and it's more meaningful to search engines.

In a perfect world you'd have a logical structure like

/images/dishes/moules-de-mariniere.jpg

where the dish / restaurant name is a unique slug. That's pretty much impossible to implement in the real world, though, so

/images/dishes/id/moules-de-mariniere.jpg

is a fair compromise to avoid collisions.

Thumbs I generally put under their own thumbs/ directory so I can use the same filenames in all locations (laziness more than anything):

/images/dishes/id/thumbs/moules-de-mariniere.jpg

but thenduks' prepending suggestion works too, it's really just personal preference.

hollsk