I hope you are well.
I am creating a Learning Platform in pure PHP with MySQL and AdminLTE3.
I got to the time of creating the file manager for each user and got stuck on the following.
I have the following structure in folders:
/var/www/html/uploads/users/<% hash (USER ID)%>
, and what I’m looking for is that each folder <% hash (USER ID)%>
the maximum size is 2GB for each user.
I am using MacOs BigSur for development, but in production it will be on Ubuntu Server 18!
I am not trying set the max_file_size_upload
, I am trying to set the maximum size of each user’s folder to 2gb
Advertisement
Answer
Which type of files will it be? I would be a very wary of allowing users to upload arbitrary files to my web server. If they upload a .php
file they would be able to run anything as the user running the webserver.
In fact, I would keep them in a database, and have fields to create the meta data instead. this way, you can compress and save the files, and store the size and filename as meta data. If you are using if for reference, etc, which does not need quick access, I would recommend this.
Alternatively, as this this linux.SE answer states, you could create a mounted folder for each user, and have the filesystem sort out everything regarding the quota. I would probably also look into chroot
ing the folders in some way. This would (in theory) also allow you to give them sftp
/ssh
access to the files.
I Would also look into doing everything in an environment similar to your production server. vagrant and docker spring to mind.
Alternatively, if all file uploads are handled by php, you could save the used file space and keep a running total, making sure in your php sript that they are nmot exceeding their quota.