I use the form to upload files to my site. I want to allow them to upload multiple photos at once, so I use the "multiple" attribute of HTML5.
My HTML:
<form method="post" action="save.php"> <input type="file" name="uploads[]" multiple="multiple" /> <input type="submit" name="submit" value="submit"/> </form>
save.php:
<?php foreach ($_FILES['uploads']['name'] as $file) { echo $file . "<br/>"; $file= time() . $_FILES['uploads']['name']; $target= UPLOADPATH . $file; move_uploaded_file($_FILES['uploads']['tmp_name'], $target) or die('error with query 2'); }
But for some reason, when I run the script, I get an undefined index: uploads error message. And an error saying that I have an invalid argument provided by foreach (). What can i do wrong?
thanks
UPDATE
Ok by setting enctype="mulitpart/form-data" . Now I am having problems moving the file. I get an error move_uploaded_file() expects parameter 1 to be string, array given . What am I doing wrong here?
Thanks again
source share