0

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)
2
  • I assume that "----> [Line 25 in file]" is not part of the code? Commented Apr 23, 2012 at 16:21
  • @Brendon Cheves, ya, u right!! Commented Apr 23, 2012 at 16:26

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.