Your input should be like this, when you upload and posting mutiple image files
<input type='file' name='attachPhoto1[]' multiple />
and your form should be like this
<form action="" method="post" name="" id="" enctype="multipart/form-data">
and following is very much working code i used, you can adjust it according to your need;
if(!empty($_FILES['attachPhoto1']['name'])) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$error_uploads = 0;
$total_uploads = array();
$upload_path = 'upload/';
foreach($_FILES['attachPhoto1']['name'] as $key => $value) {
$temp = explode(".", $_FILES['attachPhoto1']['name'][$key]);
$extension = end($temp);
if ($_FILES["files"]["type"][$key] != "image/gif"
&& $_FILES["files"]["type"][$key] != "image/jpeg"
&& $_FILES["files"]["type"][$key] != "image/jpg"
&& $_FILES["files"]["type"][$key] != "image/pjpeg"
&& $_FILES["files"]["type"][$key] != "image/x-png"
&& $_FILES["files"]["type"][$key] != "image/png"
&& !in_array($extension, $allowedExts)) {
$error_uploads++;
continue;
}
$file_name = time().rand(1,5).rand(6,10).'_'.str_replace(' ', '_', $_FILES["attachPhoto1"]['name'][$key]);
if(move_uploaded_file($_FILES["attachPhoto1"]['tmp_name'][$key], $upload_path.$file_name)) {
$total_uploads[] = $file_name;
} else {
$error_uploads++;
}
}
if(sizeof($total_uploads)) {
//Do what ever you like after file uploads, you can run query here to save it in database or set redirection after success upload
}
}
}