Question

I am in the process of creating a webpage that will allow the user to upload video/mp3/images. I have been browsing around looking for something that would point me in the right direction but have nothing that has helped clear this up.

Would it be more effective to set up a new directory for each user when the account is made or to keep the files in one folder for the corresponding file type?

EXAMPLE 1:

htdocs/user/media/image

htdocs/user/media/video

htdocs/user/media/audio

it seems that this option would allow for quicker updates for each user once they are already logged in but would mean for alot of new folders if I get a lot of people joining the site.

Example 2:

htdocs/media/image

htdocs/media/video

htdocs/media/audio

this option seems could get out of hand very quickly and could effect the speed of accessing the files.

Was it helpful?

Solution

It all matters what your application will be doing.

I think the best thing for your application would be to generate a random name for each picture being uploaded then create a nested folder structure to store the images. For example if a user uploads a photo and you assign it the name 1234.png. You can then store this picture in the folder structure //1/2/1234.png, similarly, ab234.png would be stored in //a/b/ab234.png. This structure allows for growth, minimizes the number of folders, and minimizes the number of files per folder.

To index the files you can use a MySql database. Within the MySql database you can have a table that links userIds to picture locations on disk. Your table would would have a few columns . For user '1' with picture 1234.png, the table entry would be <1,1234.png,a/b>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top