I'm working on a system and we need to do some refactoring on the upload service, that handles all files and images uploads to the system. Nothing fancy, but I it got me thinking about the folder structure we are using, and how others do, if there is any benefits doing one way or another.
For example, the folder structure we currently use in our server is:
- assets/
- images/
/- Images that are static, such as the website logo, favicon, etc..
- gallery/
/- Images uploaded by the users {jpg, png, webp}
- files/
/- Files uploaded by the users {pdf, txt, csv, xml}
Other services, Wordpress for example, stores it in a folder structure split by year and month.
Is there any benefits doing one way or the other? Even other structures not mentioned here? Either in terms of code development or even performance.
Just to mention, I'm using PHP and MySql on the backend, so for each file/image uploaded, we do a hash to name the file on the server, so if an image is called cute-dog.jpg on the server it would be something like 123456789abc.jpg. Then, on the database, we store original name, hashed name as well as the key and path to remove the image when necessary.