I am implementing an image upload system in PHP, The following are required:
For that, I have 2 approaches in mind:
Each category will have its own folder, and PHP will detect categories via those folders.
Each image in the database will have a catID (or multiple catIDs), and PHP will query the database to get the images
Which do you think is better? Or is there a third, completely different, approach that I'm missing?
Just a note, I don't need code, I can implement that myself, I'm looking to find what to implement.
Would love to hear from you.
I believe that the second option is better, a DB is giving you much more flexibility, and I think better performance then file system, if you set the right indexes.
In the filesystem approach you are limited to only 1 category per image, when in the DB you can set multiple categories on an image.
The con that Db is more messy, sorry I can't find a reason way in the db it will be more messy, maybe you mean that the files are not organized on the file system, but you still need to organize the files on the file system and divide them to multiple folders for better performance, and if you want to get all the images that have been uploaded you query the db for all of them, which will be much faster then ls on all the categories folders.
In organize the files in the file system when using the DB approach I mean that you need to divide them to several folders, actually it depends on how you predict the upload of the images will be:
The second con that need to query the DB a lot is not quite true, cause you will need the same amount of queries on the file system which are far more slower.
Good luck.
PS Don't you forget to generate a new file name to any image that have been uploaded so there will be no collisions in different users uploaded same image name, or the same user.
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