The short version:
When a user uploads a file using a form, an array is saved in the global variable $_FILES
. For example, when using:
<input type="file" name="myfiles0" />
the global variable looks like this:
$_FILES = [
'myfiles0' => [
'name' => 'image-1.jpg',
'type' => 'image/jpeg',
'tmp_name' => '[path-to]/tmp/php/phptiV897',
'error' => 0,
'size' => 92738,
],
]
In principle, I need to know which of the keys of the array $_FILES['myfiles0']
always exists and (maybe) is always set, no matter how the other keys look like, or which browser is used. Could you please tell me?
Please take into the consideration, that the $_FILES
variable can also contain multi-dimensional arrays for files uploaded using an array notation, like this:
<input type="file" name="myfiles1[demo][images][]" multiple />
The long version:
For my implemention of PSR-7 Uploaded files I need to do the normalization of the uploaded files list. The initial list can be provided by the user, or can be the result of a standard file upload using a form, e.g. the $_FILES
global variable. For the normalization process I need to check for the existence and "correctness" (maybe a poor choice of the word) of one of the following standard file upload keys:
name
type
tmp_name
error
size
In principle, if, in the provided uploaded files list (which can be a multi-dimensional array as well), the chosen key (I choosed tmp_name
for now) is found, then it will be supposed that the array item to which the key belongs is a standard file upload array item, containing the above key list. Otherwise, e.g. if the chosen key is not found, it will be supposed that the corresponding array item is an instance of UploadedFileInterface.
Unfortunately, in case of a standard file upload, I can't find nowhere a solide information about which key (from the above list) always exists and (maybe) is always set in the $_FILES
variable, no matter how the other list keys look like, or which browser is used.
I would appreciate, if you could help me in this matter.
Thank you.