0

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)."
linuxoid
  • 1,415
  • 3
  • 14
  • 32
  • Check [this](https://gist.github.com/svizion/2343619), you can use `ini_get("upload_max_filesize");` aswell, more answers [here](https://stackoverflow.com/questions/13076480/php-get-actual-maximum-upload-size/25370978) – Burhan Kashour Nov 08 '20 at 12:01
  • You seem to miss my point - I know how to get the php max values, the problem is if the uploading file is greater then that, the files array is NULL so I don't even get to know its size and compare it to the limit. e.g. the upload_max_filesize = 2MB and the file is 10MB. How do you get the file's size if the files array is NULL, it simply doesn't upload by the script – linuxoid Nov 08 '20 at 12:08
  • `PHP` is checking the `file size` once its uploaded, if you an empty or null `array` , then check how you pass data for any possible `errors`! – Burhan Kashour Nov 08 '20 at 12:11
  • ok, I got it (updated above) – linuxoid Nov 08 '20 at 12:15
  • 1
    You still need to add the `getErrorMessage()` function to your code – Burhan Kashour Nov 08 '20 at 12:25
  • Does this answer your question? [Get file size before uploading](https://stackoverflow.com/questions/7497404/get-file-size-before-uploading) – Ro Achterberg Nov 08 '20 at 12:31
  • well, that's half of the problem, that only catches the upload_max_filesize. How do I catch the post_max_size and max_file_uploads? – linuxoid Nov 08 '20 at 12:34

0 Answers0