Grigor
Grigor

Reputation: 4059

MySQL users and folders

I have a website where users sign up and get to upload their images and videos for their portfolio. Each user is shown under some criteria and when visitors click on their names they see the portfolio.

My question is: which is better, having folders for each user (upon signing up creating folders with unique_id of their name or some sort) so that they can upload their images and videos in there or renaming the uploaded files and putting everything in one folder. Or store the images straight in database with binary blob conversion?

Upvotes: 2

Views: 140

Answers (2)

Luc Franken
Luc Franken

Reputation: 3014

File or database is duplicate as already noted.

About file storage:

There are many different ways to execute this. It depends on the performance needed, the amount of users, amount of files etc.

For example, if one person would be uploading hundreds of thousands of files it would not be smart to put them all in one folder.

If you have millions of users you don't want a structure like: userdata/{userid}/ because you would get millions folders within userdata/. That would also give possible issues.

For example you could implement some kind of sharding approach by saving the userdata on different servers. So lots of options possible when choosing for "just saving as normal files".

Upvotes: 1

Icarus
Icarus

Reputation: 63962

From a performance perspective I would think that having a directory per user is better. The max limitation of directories on NTFS partitions seems to be over 4 billion which should be more than enough for any app.

If you use Linux/Unix, the max # of folders you can have will vary on the type of partition as well but if NTF's limit is big enough, I imagine ext3 or any of the journalised file systems should have an ample limit as well.

Regarding whether is better to store images on the DB or the file system, other people have pointed out a well-known related question here. My take is that, generally, either solution works good and both have pros and cons as to make the decision ultimately pretty much a matter of taste.

Upvotes: 1

Related Questions