0

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.

dax
  • 10,779
  • 8
  • 51
  • 86
Andrew.W
  • 3
  • 2

1 Answers1

0

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>

milk3422
  • 660
  • 6
  • 10
  • Would all of a particular users media be stored in the same folder structure (ie. a/b/) or would each upload have random folder structure and the table just track what images belong to each user and just grab them from all over the place? is this similar to how facebook use to store images (prior to the haystack method)? I recall saving pictures from there and having the name have 50+ random characters. – Andrew.W Sep 19 '13 at 17:17
  • Each upload would have random folder structure and the table just track what images belong to each user and just grab them from all over the place. This is how a lot of companies/small projects store data because it is very easy and expands quite well. Once you get into the 100's of millions range, you might want to adjust how images are stored. I also suggest that as images are imported you reformat the images to all be a standard size and possibly even create multiple versions (smaller sizes to use as thumbnails, etc.) – milk3422 Sep 19 '13 at 17:59
  • I suppose if I get into the millions, I will have bigger fish to fry anyways. One more question, any suggestions on the best way to secure the users files in a structure like this? – Andrew.W Sep 19 '13 at 18:15
  • When you use MySQL to access the files users pictures will only be accessible to the userIds which are linked to the file. In reality, no users would have access to any file except the files that their userId knows about in MySql. Only root, or a privileged account would have access to all of the files. – milk3422 Sep 19 '13 at 18:47