<form action="" method="post" enctype="multipart/form-data"> 请选择要上传的文件:<input type="file" name="myFile" value="" /> <input type="submit" value="开始上传" /> </form> <?php header("content-type:text/html;charset=utf-8"); echo "<pre>"; print_r($_FILES); echo "</pre><hr/>"; $name=$_FILES['myFile']['name']; $type=$_FILES['myFile']['type']; $tmp_name=$_FILES['myFile']['tmp_name']; $error=$_FILES['myFile']['error']; $size=$_FILES['myFile']['size']; if($error==UPLOAD_ERR_OK){ if(is_uploaded_file($tmp_name)){ @$ext=strtolower(end(explode(".", $name))); $extArray=array("jpeg","png","gif","jpg","txt"); if(in_array($ext, $extArray)&&substr($type, 0,5)=='p_w_picpath'){ //in_array函数是区分大小写的 $uniqueName=md5(uniqid(microtime(true),true)); $dir="p_w_picpaths"; $destination=$dir."/".$uniqueName.".".$ext; if(move_uploaded_file($tmp_name, $destination)){ $mesErr="上传成功"; }else{ $mesErr="上传失败"; } }else{ $mesErr="不支持文件类型,请重新选择文件上传"; } }else{ $mesErr="非法上传方式"; } alertErr($mesErr); }else{ //echo $error; switch($error){ case 1: $mesErr="超过了配置文件设定的大小!"; break; case 2: $mesErr="超过了POST缓存的最大值!"; break; case 3: $mesErr="只有部分文件被上传!"; break; case 4: $mesErr="没有文件被上传!"; break; case 5: $mesErr="上传文件大小为0!"; break; case 6: case 7: case 8: $mesErr="未知错误!!!"; break; default: $mesErr="上传失败!"; break; } alertErr($mesErr); } //Java警告 function alertErr($mesErr){ echo "<script type='text/javascript'>alert('{$mesErr}')</script>"; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。