Missing tmp_name field in $_FILES array

when I pass some files to a .php using a <input type="file" id="file-upload" name="userfile[]" multiple required> in a html form, using the official php:8.1-apache image, I don’t get the last ['tmp_name'] but when I use apache directly I don’t have this problem.
More specifically $_FILES['userfile']['tmp_name'][count($_FILES['userfile']['tmp_name'])-1] == "".
For example when inputting 4 file:

foreach ($_FILES['userfile']['tmp_name'] as $key => $name) { 
   echo $key." => ".$name;

will print:

0 => /tmp/php8FKarG
1 => /tmp/phpOhH1yJ
2 => /tmp/phprieejH
3 => 

Using directly apache I get:

0 => C:\xampp\tmp\php6B03.tmp
1 => C:\xampp\tmp\php6B04.tmp
2 => C:\xampp\tmp\php6B05.tmp
3 => C:\xampp\tmp\php6B16.tmp

Doing the same with ['name'] returns the correct filename of all 4 files in both cases but not with ['tmp_name'] that is missing most of the times on the last element when using docker.
Why does this happen?

The fact that you try it in a container should not matter. Your last file is probably too large to upload or some other error happened. Try to chck the error code $_FILES['userfile']['error']

If the file is too large, you need to change the upload_max_filesize or post_max_size

1 Like

Thank you, that was the problem, I was getting a 1 error on the last file