Demo entry 6685982

up

   

Submitted by anonymous on Dec 22, 2017 at 06:41
Language: PHP. Code size: 922 Bytes.

<?php
header('Content-Type:text/html;charset=utf-8');
echo  '<pre>';
//多张图片
if(!empty($_POST)&&isset($_POST)){
	    // print_r($_FILES);
	foreach ($_FILES as $key => $value){
	  	// print_r($_FILES[$key]['name']);
		$type=array('jpg','png','gif','jpeg');
	 	$img_type=$_FILES[$key]['name'];
	 	$img_error=$_FILES[$key]['error'];
	 	$size=$_FILES[$key]['size'];
	 	$ex=explode('.',$img_type);
	 	$end=end($ex);
 		// echo $end;
 	 	// var_dump(in_array($end,$type));
 		if(in_array($end,$type)&&$size <5242880&&$img_error==0){
 			//以当前时间创建文件
	   		if(file_exists('upload')==0){
	   			mkdir('upload');
	   		}
	   		// echo $_FILES[$key]['name'];die;
			move_uploaded_file($_FILES[$key]['tmp_name'], './upload/'.$_FILES[$key]['name']);
			//$_FILES['img']['name']
			echo "<script>alert('上传成功');location='form2.html'</script>";
	   	}else{
	   		echo '上传失败';
	   	return false;
	   }
	}
}
?>

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).