How to check files for upload_max_filesize and post_max_size prior to upload?

172 views Asked by At

How can I check uploading files for upload_max_filesize, post_max_size and max_file_uploads on the server side? If files are bigger than these values, they don't even get to the file array. So I obviously can't get the files sizes and compare them to values. How can I prevent file uploads which are bigger than these?

Some say the error may be obtained from $_FILES['file']['error']. So if I get the files as

$this->request->files->get('my_file')
foreach ($files as $file) {
...

how do I get that error?

[UPDATE} Working solution for upload_max_filesize:

$file->getErrorMessage();

The error I get :

"The file "2.6MB.avi" exceeds your upload_max_filesize ini directive (limit is 2048 KiB)."
0

There are 0 answers