<html><head><h2>MultiFile Upload</h2></head><form action="" method="POST" enctype="multipart/form-data"><?php for($i = 0; $i <5; $i ++):?> <p><input type="file" name="image[]"></p><?php endfor;?><input type="submit" name="upload" value="Upload"></form></html>
function upload_image(){ for($i=0; $i<5; $i++){ $fileupload = $_FILES['image']['name'][$i]; $path_thub = './thub_image/'; $path_image = './images/'.$fileupload; $max_width = 200; $max_height = 160; if(trim($fileupload) != '' ){ $ext = getExt($fileupload); $ext_upload = array('jpg','jpeg','png','bmp','gif'); if(in_array($ext,$ext_upload)){ move_uploaded_file($_FILES['image']['tmp_name'][$i],$path_image); list($width,$height) = getimagesize($path_image); //kiểm tra nếu file upload nhỏ hơn kích thước quy định thì lấy kích thước cũ. if($width < $max_width && $height < $max_height){ $new_width = $width; $new_height = $height; }else{ $sx = $width/$max_width; $sy = $height/$max_height; //resize theo tỷ lệ. if ($width > $height) { $new_height = round($height/$sx, 0); $new_width = $max_width; } else { $new_width = round($width/$sy, 0); $new_height = $max_height; } } $image_thub = imagecreatetruecolor($new_width,$new_height); switch($ext){ case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($path_image); break; case 'png': $image = imagecreatefrompng($path_image); break; case 'gif': $image = imagecreatefromgif($path_image); break; default: $image = imagecreatefromjpeg($path_image); break; } imagecopyresampled($image_thub,$image,0,0,0,0,$new_width,$new_height,$width,$height); $thumb_file = 'thumb_'.$_FILES['image']['name'][$i]; $tmp_content = imagejpeg($image_thub, $path_thub.$thumb_file, 100); } else{ echo 'File khong hop le'; } } }}function getExt($filename){ return $ext = strtolower(substr(strrchr($filename,'.'),1));}