1 if(!empty($userfile)){ 2 $userfile = $_FILES["userfile"]; 3 $type_arr = array("jpeg", "jpg", "png", "gif"); 4 var_dump($userfile); 5 $dir = "./upload"; 6 if(!is_dir($dir)){ 7 mkdir($dir); 8 } 9 10 for($i=0; $i<count($userfile["name"]); $i++){ 11 $type=explode("/", $userfile["type"][$i]); 12 $filename = $dir."/".date('YmdHis',time()).mt_rand().".".$type[1]; 13 14 if($userfile["error"][$i] == UPLOAD_ERR_OK){ 15 if($userfile["tmp_name"][$i] != ""){ 16 if(in_array($type[1], $type_arr)){ 17 if(move_uploaded_file($userfile["tmp_name"][$i], $filename)){ 18 echo $userfile["name"][$i]."上传成功"."<br/>"; 19 }else{ 20 echo $userfile["name"][$i]."上传失败"; 21 } 22 } 23 } 24 } 25 26 27 } 28 29 }