I want to select more image files at a one time and upload as 1,2,3,4,… Like:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="imgs[]" id="imgs" multiple/>
<input type="submit" name="submit" value="Submit" />
</form>
PHP code:
<?php
if (file_exists("upload/" . $_FILES["imgs"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
//I think loop goes here
===================
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
===================
}
?>
==================================================================
This is works…
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploads[]" multiple>
<input type="submit" name="submit" value="Submit" />
</form>
PHP
<?php
$count=1;
foreach ($_FILES['uploads']['tmp_name'] as $file) {
echo '<li>' . $file . '</li>';
copy($file, "uploads/" . $count.".jpg");
echo "Stored in: " . "uploads/" . $count.".jpg";
$count++;
}
?>
this is works….
PHP build the
$_FILESarray in a strange (but consistent) way when you have multiple upload. Try creating this form with three file inputs:Then in the PHP code that receive your form, place only:
So you can see the
$_FILESarray structure. At this point all will be clear to you, and you will get yourself how to loop on it to save all uploaded images. Good luck 😉