Reputation: 20178
HTML for the file uplods:
<form enctype="multipart/form-data" action="" method="POST">
<br/>Upload Featured Image: <input name="imagefiles" type="file" /><br/>
<br/>Upload Gallery Image 1: <input name="imagefiles" type="file" /><br/>
<br/>
<input type="submit" name="submit" value="Add Product" />
</form>
To handle the upload, I'm doing this:
$imagefiles = $_FILES['imagefiles'];
foreach ($imagefiles['name'] as $key => $value) ----> [Line 25 in file]
{
}
But, I'm getting this error:
Warning: Invalid argument supplied for foreach() in /var/www/html/addProductForm.php on line 25 (Edit)
Upvotes: 0
Views: 234
Reputation: 6470
you are not using correct parameter names.
You have to add []
to make your input an array, otherwise the last element will override previous elements with same name..
Try HTML below:
<form enctype="multipart/form-data" action="" method="POST">
<br/>Upload Featured Image: <input name="imagefiles[]" type="file" /><br/>
<br/>Upload Gallery Image 1: <input name="imagefiles[]" type="file" /><br/>
<br/>
<input type="submit" name="submit" value="Add Product" />
</form>
Upvotes: 1