Viet Anh
Viet Anh

Reputation: 139

Structure of folder for uploaded files

I am implementing a website which allows users to upload their files. I wonder how the upload folder should be structured so that I can manage the uploaded files easily in the future. Should I provide different users with different sub-folders (for example, upload/user1 for user1, upload/user2 for user2, etc.) or should I just put them all in the same folder? And should I rename the uploaded files? (I know that a lot of websites do this!)

Upvotes: 2

Views: 1064

Answers (2)

Exander
Exander

Reputation: 882

If you won't be using BLOB, and the users may have an arbitrary number of images, then I think you should be using the subfolders. For instance, you could create a subfolder named after the user's id. One of the reasons for this is that when the folder contains A LOT of files, the access times increase as it takes more time to find the file with specified name. You could also rename the files when they're stored just so that there would be no chance of their names overlapping. Just don't forget to store the newly-generated names in the DB.

Upvotes: 1

DanRedux
DanRedux

Reputation: 9349

Renaming them can be useful if you ever want to "hide" them to anyone not logged in, for example. Just store their original name in a DB.

Also, you can always store it all in a SQL table in a BLOB type.. Can be several GB and lets you relate a filename, username, whatever else.

Upvotes: 0

Related Questions