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
- Saving Account
- Fixed Deposit
Now for Every Fixed Deposit i need to store the
- scanned image of that FD
- one or more images for source of money like Bank Cheques
Now where should i store all those images. I mean
- Do I need to create folder for each user then each FD and then sources
- Or All images in one folder
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.