First note that in your array
not the key name
or tmp_name
which is common when using $_FILES
in PHP.
This way I know you must be using the wrong method to capture the form data. (You must be using $_POST
).
Usually when you want to make one upload file(s), if used :
<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="file" name="imagens[$id][]">
</form>
Note that in the form this method="post"
, however in PHP you should capture it by $_FILES
. What should generate an array like this :
Array
(
[45] => Array
(
[0] => Array
(
[name] => 1.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[size] => 98174
)
[1] => Array
(
[name] => 2.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[size] => 98174
)
)
[44] => Array
(
[0] => Array
(
[name] => 4.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[size] => 98174
)
)
)
To manipulate your content you can use foreach
:
foreach($_FILES as $id => $files){
foreach($files as $k => $file){
$name = $file['name'];
$tmpName = $file['tmp_name'];
printf("name : %s\n tmpName : %s", $name, $tmpName);
}
}
$_FILES['imagens'][0]['tmp_name']
, in the doubt of aprint_r($_FILES);
– rray
Uses a
echo <pre>;
withprint_r($array);
instead ofvar_dump
, this bad to read.– Guilherme Lautert
Hello @Guilhermelautert , updated this way
– Ricardo Afonso