";
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函數(shù)是區(qū)分大小寫的
$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="不支持文件類型,請(qǐng)重新選擇文件上傳";
}
}else{
$mesErr="非法上傳方式";
}
alertErr($mesErr);
}else{
//echo $error;
switch($error){
case 1:
$mesErr="超過了配置文件設(shè)定的大??!";
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="未知錯(cuò)誤?。?!";
break;
default:
$mesErr="上傳失??!";
break;
}
alertErr($mesErr);
}
//Java警告
function alertErr($mesErr){
echo "";
}
網(wǎng)頁名稱:上傳文件函數(shù)的思路
本文網(wǎng)址:
http://weahome.cn/article/gcjjje.html