I've created a form for multi-file upload. I report here only the required code, of it.
when I upload one or more files, the array
$_FILES['shopImage']
has the date related the one or more files,
and I can see it through the var_dump()
I put into the PHP code here below
I can spot the uploaded file.
however, the function
is_uploaded_file($_FILES['shopImage']['tmp_name'])
returns always FALSE.
Please here the HTML code that generates the $_FILES array:
<form method="POST" action="upload.php" enctype="multipart/form-data">
...
...
...
<div class="pics">
<input type="file" name="shopImage[]">
<input type="file" name="shopImage[]">
<input type="file" name="shopImage[]">
<input type="file" name="shopImage[]">
</div>
...
...
...
<input type="submit" name="submit" value="UPDATE"><input type="reset" value="RESET">
</form>
Here the PHP code I used to test it:
<?
require_once $_SERVER['DOCUMENT_ROOT'].'include/setup.php';
if (!empty($_POST['submit']) and $_POST['submit'] == "UPDATE") {
var_dump($_FILES['shopImage']);
if(is_uploaded_file($_FILES['shopImage']['tmp_name'])){
echo "TRUE";
exit;
} else {
echo "FALSE";
exit;
}
}
?>
And here here the var_dump()
array(5) {
["name"]=>
array(10) {
[0]=>
string(11) "Logo.png"
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(0) ""
}
["type"]=>
array(10) {
[0]=>
string(9) "image/png"
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(0) ""
}
["tmp_name"]=>
array(10) {
[0]=>
string(14) "/tmp/php2TOmvR"
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(0) ""
}
["error"]=>
array(10) {
[0]=>
int(0)
[1]=>
int(4)
[2]=>
int(4)
[3]=>
int(4)
}
["size"]=>
array(10) {
[0]=>
int(21947)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
}
}
NOTE: I did check a quite similar issue here, but the conditions described, are not the same of mine. I didn't implement yet move_upload_file()
etc ...
Could you help me please to figure out a solution?
Thanks a lot in advance
As you can see from your var_dump
your $_FILES['shopImage']['tmp_name']
is array. So you should check elements of this array, and not the array itself. For example:
foreach ($_FILES['shopImage']['tmp_name'] as $tmp_name) {
if (is_uploaded_file($tmp_name)) {
echo 'Yes';
} else {
echo 'No';
}
}