My question is not about storing images on disk or in DB.
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;
}
The key-value store is simple storage that can be used for storing any kind of data. It can be JSON or HTML documents, zip files, images, or simply strings.
For example, suppose you have a table containing the file names of images and you also want to store the image in a bytea column: CREATE TABLE images (imgname text, img bytea); To insert an image, you would use: File file = new File("myimage.
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.
Depending on the number of images you want to handle, I would strongly suggest using several folders. The easiest way should be to use the first letter of the file name to create a folder structure. I think, the numbers are something like this:
less than 1000 images --> one folder
less than 20000 images --> one level of folders (a, b, c, ...)
more --> several levels (a containing aa, ab, b containing ba, bb, ...)
YMMV
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With