I have one simple question. Now I’m working on a e-commerce script and of course users will be able to upload images for each product (up to 10 images for each product). So my question is should I place all the images in the same directory (it will probably be thousands after a time) or create new ones from time to time? Will this slow down the performance or cause any other problems in future if I place them all together?
Thanks in advance
Disk approach
Create an
imgparent directory, with a subdirectory for each product’s images.This way you’ll have all your images stored in a single tree hierarchy that makes good sense. If you’re going to have a very large amount if images (say, more than 100,000) you can group the images according to creation date:
This way, you will be able to move some months (probably the older ones) to an archive and keep the month subdirectory as a link to another disk.
Database approach
If you need to keep a lot of metadata on each image (e.g., username, SKU, description, copyright etc) you can store the images using arbitrary image names (probably
img/img0000001.jpg,/img/img0000002.jpg, …) and keep a database record that maps a product to its image. This is very useful for searching all the images with a certain characteristics (user, creation date, etc.) associated with them.