Storing file information in a database

1.9k Views Asked by At

I am building a file hosting site and would like to keep track of users file quota ( Each user is only allowed 2gb of file storage). Could anyone explain how I could store file name, type and importantly size of all files uploaded by a user in a mysql database. And is it possible to calculate using php script or MySQL when users exceed limit, display a message and reject any further uploads until files have been deleted by them to reduce quota?

I am fairly new to mySQl and would really appreciate some simple guides on how to achieve this.

Thanks

R

1

There are 1 best solutions below

3
On

...is it possible to calculate using php script or MySQL when users exceed limit, display a message and reject any further uploads until files have been deleted by them to reduce quota?

Short Answer

Yes.

Long Answer

Yes but it will take some coding.

I recommend:

  • Use PHP for the file-handling side of things
  • Store information about the files in your MySQL database

You definitely can store the file name, file type and size of each file in your database.

You can use this data to ensure that a user has quota remaining, and warn / block them when they try to upload files once they've reached their quota.

If you're new to MySQL / PHP, then this sounds like a great project to get you started with both.

I recommend the Tizag tutorials: PHP / MySQL.

Once you've covered the basics, please read about database normalization.

Edit: to find the size of a file with PHP, use filesize.