$uptypes=array( //Upload file ContentType format 'image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x- png', 'application/msword',//doc 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',//docx 'application/vnd.openxmlformats-officedocument.presentationml.presentation',//pptx 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',//xlsx 'text/plain' ); /** * PHP multi-file, multi-image upload * by bbs.it-home.org */ $max_file_size=2000000; //Upload file size limit, unit BYTE $dir="upload/"; //Upload file path if ($_SERVER['REQUEST_METHOD'] == 'POST') { $file = $_FILES['upfile']['name']; foreach($file as $key=>$item){
if($item != ''){
if (!is_uploaded_file($_FILES['upfile']['tmp_name'][$key]))/ /Whether the file exists
{
echo "The picture does not exist!";
exit;
}
if($max_file_size < $_FILES['upfile']['size'][$key])//Check the file size { echo "The file is too big!"; exit; } if(!file_exists($dir)) { mkdir($dir); } $filename=$_FILES['upfile']['tmp_name '][$key]; $image_size = getimagesize($filename); $pinfo = pathinfo($file[$key]); $ftype = $pinfo['extension']; $destination = $dir .time().$file[$key]; if (file_exists($destination) && $overwrite != true) { echo "The file with the same name already exists"; exit; } if(!move_uploaded_file ($filename, $destination)) { echo "Error moving file"; exit; } $pinfo=pathinfo($destination); $fname=$pinfo['basename']; echo " < font color=red>has been successfully uploaded File name: ".$dir.$fname." ";
echo " Width: ".$image_size[0];
echo " Length: ".$image_size[1];
echo " Size: ".$_FILES['upfile']['size']." bytes" ;
}
echo " Image preview: ";
echo " ";
echo " ";
}
}
?>
< input type="submit" name="submit" id="submit" value="button"/>
Copy code
Instructions:
When uploading, you need to upload two, otherwise an error will be reported.
The code is not very complete, it just gives an idea for learning reference only.