上传文件函数的思路
";
print_r($_FILES);
echo "
"; $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 ""; }
当前题目:上传文件函数的思路
网页地址:http://scjbc.cn/article/gcjjje.html
"; $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 ""; }
当前题目:上传文件函数的思路
网页地址:http://scjbc.cn/article/gcjjje.html