标签:chmod exists fun 上传文件 move uniq loaded 文件中 UNC
public function upload($fileInfo, $maxSize, $allowExt) {
$error = $fileInfo[‘error‘];
if($fileInfo[‘error‘]>0){
switch ($error) {
case 1:
$msg= ‘上传文件超过了PHP配置文件中upload_max_filesize选项的值‘;
break;
case 2:
$msg= ‘超过了表单MAX_FTLE_SIZE限制的大小‘;
break;
case 3:
$msg=‘文件部分被上传‘;
break;
case 4:
$msg= ‘没有选择上传文件‘;
break;
case 6:
$msg= ‘没有找到临时目录‘;
break;
case 7:
case 8:
$msg= ‘系统错误‘;
break;
}
echo $msg;
}
//1,检测非法文件类型
$ext = pathinfo($fileInfo[‘name‘],PATHINFO_EXTENSION);
//2,判断上传文件的大小
if($fileInfo[‘size‘]>$maxSize){
echo ‘上传文件过大‘;
}
if (!in_array($ext, $allowExt)) {
echo ‘文件格式错误‘;
}
$uploadPath = PRJ_PATH . ‘/uploads‘;
if(!file_exists($uploadPath)){
mkdir($uploadPath,0777,true);
chmod($uploadPath,0777);
}
$uriName = $fileInfo[‘name‘];
$resume_path = md5(uniqid($uriName)) . ‘/‘.$uriName;
if(move_uploaded_file($fileInfo[‘tmp_name‘], $resume_path)){
echo ‘文件上传成功‘;
}else{
echo ‘文件上传失败‘;
}
return $resume_path;
}
标签:chmod exists fun 上传文件 move uniq loaded 文件中 UNC
原文地址:https://www.cnblogs.com/zjmbk/p/9450903.html