Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store large amount of data of users

I store files of users in their own name directory something like

/username/file01.jpg
/username/file02.mp4
/username/file03.mp3

But if more users come and upload more files then this creates problem because this will lead to migration of some or many users to another drive.I choose username directory solution first because i dont want filenames to be mixed. I dont want to change filename too. Also if another user upload same filename then it creates problem ,if the files are stored with original name.

What could be the best way to do this. I have one solution but want to ask community is this the best way .

i will use sequential folders and then hash the file name to some thing very unique and store into the directory. What i will do is store the original name of file and username into database and hashvalue of filename which is stored in Disk.

When anyone want to access that file,I will read that file through php either replace the name or will do something at that point so that the file is downloaded as original filename.

I have only this proposed solution in mind. Do you guys have any other better than this one.

Edit:

I use folder system too, and possibly for 2nd way i will use virtual folders. My database is MongoDB

Guys all your answers were awesome and really helpful. i wanted to give bounty to everyone, thats why i left it so that community can provide automatically. Thanks all for your answers.I really appreciate it.

like image 228
Abhishek Avatar asked Apr 03 '13 21:04

Abhishek


1 Answers

Could you create relational MySQL tables? e.g.:

A users table and a files table.

Your users table would keep track of everything you are (I assume) already tracking:

id, name, email, etc.

Then the files table would store something like:

id, fileExtension, fileSize, userID <---- userID would be the foreign key pointing to the id field in the files table.

then when you save your file you could save it as it's id.fileExtension and use a query to pull the user associated with that file, or all files associated with a user.

e.g.:

SELECT users.name, files.id, files.extension
FROM `users`
INNER JOIN `files` on users.id = files.userID;
like image 200
drewwyatt Avatar answered Sep 28 '22 05:09

drewwyatt