All the fields (even the empty ones) get sent to the server and each field will have an array entry with its information (tmp_name
, name
, size
, error
, ...) although it's empty.
Just check $_FILES['attach']['error'][$i]
against the UPLOAD_ERR_NO_FILE
(int: 4) constant.
For more information about file upload error messages see the official PHP manual page.
Please note that for a bunch of files with the same name <input type="file" name="attach[]">
the array will look like this (in this case for three file input fields):
$_FILES['attach'] => array(
'name' => array(
0 => 'File 1.jpg',
1 => 'File 2.pdf',
2 => ''
),
'error' => array(
0 => 0,
1 => 0,
2 => 4
),
'tmp_name' => array(
0 => 'foo',
1 => 'bar',
2 => ''
)
// ...
)