php 移动文件失败怎么办?
php文件上传,提示移动文件失败?
如:
include("../Include/Conn.php"); include("../Include/Function.php"); include("../Include/Data.php"); $uploadPage="edit_headimage.php"; $dir=$file_upload_root.'HeadImages'; # 上传的文件目录 $err_msg=false; $err_msg_behind=',请重新上传。'; if (!isset($_FILES['upfile'])) $err_msg='表单不完全'.$err_msg_behind; else $fileImg=$_FILES['upfile']; switch($fileImg['Error']){ case 1: $err_msg='文件超过最大上传限制'.$err_msg_behind; break; case 3: $err_msg='文件上传不完全'.$err_msg_behind; break; case 4: $err_msg='没有选择文件'.$err_msg_behind; break; case 2: $err_msg='文件超过页面最大上传限制'.$err_msg_behind; break; case 7: $err_msg='文件写入失败'.$err_msg_behind; break; case 6: $err_msg='没有临时文件夹'.$err_msg_behind; break; case 0: break; default: $err_msg='未知错误'.$err_msg_behind; } if (!in_array($fileImg['type'],array('image/jpeg','image/pjpeg','image/png'))) $msg="只允许上传png或jpg图片".$err_msg_behind; if (!$err_msg){ if (!move_uploaded_file($fileImg['temp_name'],$dir.$fileImg['name'])){ $err_msg='移动文件失败'.$err_msg_behind; } } if ($err_msg) error ($err_msg); else{ echo '完成'; } include("../Include/Close.php"); ?>
解决办法:
if (!move_uploaded_file($fileImg['temp_name'],$dir.$fileImg['name'])){ $err_msg='移动文件失败'.$err_msg_behind; }
move_upload_file无法移动文件
1、请确定$dir.$fileImg['name']的文件路径是否正确
$dir=$file_upload_root.'HeadImages'最后是否要加"/"
2、请确定$dir具有可写权限
我来说两句