Question

I'm going to make a files, resources manager for user. My website provide a service help user create blog, website and allow user upload their resources. I'm will create a folder structure like below. Any suggestion?

usercontents
--user1
----folder1
----folder2
--user2
--user3
----my images

Should I use database to index those files?

Was it helpful?

Solution

If I'd do something like this, firstly I would do the following:

  • restrict the file types to a few I specify (images, mp3, mp4, maybe swf);
  • normalize the user names or restrict them to alphanumeric so that I don't have user name folder conflicts;
  • normalize the filenames so that my awesome mp3 file (some comment here).mp3 turns into my-awesome-mp3-file-some-comment-here.mp3;
  • check for file name conflicts so that if an user uploads a file with the same name as a previous one no overwriting will happen (turn duplicate screenshot.png into screenshot-2.png);
  • definitely move the handling of sub folders to the database, leaving the file structure in the user directories flat.

Further optimization:

  • store file checksums in the database to avoid storing duplicate files on the file system. Limit duplicate checking to own files.

I wrote a community driven file sharing website and I think it shows. :)

OTHER TIPS

It would make sense to use a database, as then only files added through your interface would only be available to view then (presuming you're reading the file list from a database and not the actual file system).

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