Create the html for multiple file upload.The form action would go to the "uploads.php" file.
<form action="upload.php" method="post" enctype="multipart/form-data">
Select Files:
<input name="blogimg[]" type="file"/><br />
<input name="blogimg[]" type="file" /><br />
<input name="blogimg[]" type="file" /><br />
<input name="blogimg[]" type="file" /><br />
<input type="submit" value="Upload Bulk Images" name="submit">
</form>
Create a target folder to store files and a php file ie. upload.php.Here the target folder created as 'uploads' under root directory.
<?php
$target_dir = "uploads/";
if(isset($_POST["submit"])) {
/* Start of Re-arangement of Single array coming from Post */
function arrngTomultarr(&$values) {
$multi_ary = array();
$val_count = count($values['name']);
$val_keys = array_keys($values);
for ($i=0; $i<$val_count; $i++) {
foreach ($val_keys as $key) {
$multi_ary[$i][$key] = $values[$key][$i];
}
}
return $multi_ary;
}
/* End of Re-arangement of Single array coming from Post */
$multiarr_arrnged = arrngTomultarr($_FILES['blogimg']);
/* Start of Uploading images of multi-array after rearrangement */
foreach ($multiarr_arrnged as $result) {
$name = $result['name'];
if( !empty($name)){ // Check For Empty Values
$tmprary_name = $result['tmp_name'];
$temp = explode(".", $name);
$newfilename = uniqid(). '.' . end($temp);
if (move_uploaded_file($tmprary_name , $target_dir.$newfilename)) {
echo "The file ". basename( $name). " has been uploaded.<BR/>";
} else {
echo "Sorry, there was an error uploading your file.<br/>";
}
}
}
/* End of Uploading images of multiarray after rearrangement */
}
The file names will be unique so there is no need to check file existence and the empty selection will be discarded.
0 Comment(s)