Reputation: 31548
I am making the small finance management website in php. I have to store quite a few images for my application but i am confused where should i store them. My Scenario is
The user will have
Now for Every Fixed Deposit i need to store the
Now where should i store all those images. I mean
Upvotes: 0
Views: 1565
Reputation: 3681
I would definitely have a folder (user ID) per user, so you won't have to parse a giant folder of images if you're trying to load one user's images. Beyond that, I think you could just store them in a single folder and use a naming convention or group all images in a sub-folder in a way that makes the retrieval of those images easier.
Upvotes: 0
Reputation: 2262
Don't store all the images in one folder; you'll have issues once you have thousands of files in the same folder. It would make sense and divide up nicely to create a subfolder for each user.
Don't put the folder in a web accessible directory. Instead have an intermediary php script that accepts some parameters, checks whether the requesting user has privileges to view the file, and then use readfile() to return the image. That way you prevent people from viewing other people's images.
Don't use the file name of the uploaded image. Instead you could use the id of database row as the name, or create a UUID; something unique and generated by you. That way you don't have to worry about users uploading files with conflicting names or attempting to hack your system with crazy file names.
Upvotes: 3