My question is not about storing images on disk or in DB.
- Images will be stored on disk
- Image path and other image data will be saved in database.
- Images will be given a unique filename
- Images will be stored in 3 sizes
- In time there may be many images used by many users
My questions are:
– Should images be stored in one folder, or many folders?
– Is it ok to use md5 for creating unique id’s? E.g. md5(id+filename+random_num)
– Should images be cached on server or on clients browser / computer?
Anything else I should think of?
The solution is using php, apache and mysql. We use Uploadify for uploading images.
Some code I use today
/**
* Calculate dir tree for object
* Folders starts from 00 to FF (HEX) and can have just as
* many subfolders (I think :)
* @param $id - User ID
* @param $type - Image category
* @return string
*/
function calculateDirTree($id, $type)
{
$hashUserID = substr(hash('md5', $id), -4);
$parentFolder = substr($hashUserID,0,2);
$subfolder = substr($hashUserID,2);
$basePath = $type."/".$parentFolder.'/'.$subfolder.'/';
return $basePath;
}
Should images be stored in one folder, or many folders?
You are talking about “100k – 200k images” so many folders is a must have. Try to have max. ~1000 images in on folder.
Is it ok to use md5 for creating unique id’s? E.g. md5(id+filename+random_num)
Yes, you can do this. It will avoid problems with long filenames.
Should images be cached on server or on clients browser / computer?
The should be cached on the client side. The problem with so many images is that it creates high traffic. Caching on the client help reducing this.