Getting to $_FILES[]

I have a file upload input in a form

<input type="file" id="picupload" class="picupload" click-type="type2" name="Images[]" accept="image/*" multiple />

when I submit the form I use

echo '<pre>';
print_r($_POST);
echo '</pre>';

echo '<pre>';
print_r($_POST['Images']);
echo '</pre>';

the result


Why is the uploaded file not in the $_FILES

It doesn’t look like your form is being submitted as type “multipart/form-data”. Add enctype="multipart/form-data" to the <form> opening tag.

More info: http://php.net/manual/en/features.file-upload.post-method.php

2 Likes

ok, think I may have a logic error, heres my form to allow uploads


I selected 5 images to upload
But when I upload the form

Heres that page,

<?php
$upload_directory = "images/properties/".$_POST['propertyID']."/";

echo '<pre>';
print_r($_POST);          
echo '</pre>';

echo '<pre>';
print_r($_FILES['Images']);
echo '</pre>';

//loop through an array of all the images
foreach($_FILES['Images']['name'] as $image)
{
	echo $image;
	...
}

why doesnt the 2nd array show all the images and not only 1?

there must be something missing in the codes you posted, this works:

<?php

echo '<pre>';
print_r($_POST);          
echo '</pre>';

echo '<pre>';
print_r($_FILES);
echo '</pre>';

?>

<form enctype="multipart/form-data" method="POST">
<input type="file" id="picupload" class="picupload" click-type="type2" name="Images[]" accept="image/*" multiple />
<input type="submit" />
</form>
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.