本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。php 移动文件失败怎么办?php文件上传,提示移动文件失败?如:<?php include("../Include/Conn.php");
本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。
php 移动文件失败怎么办?
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=',请重新<a href="'.$uploadPage.'">上传</a>。';
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无法移动文件
请确定$dir.$fileImg['name']的文件路径是否正确
$dir=$file_upload_root.'HeadImages'最后是否要加"/"
请确定$dir具有可写权限
--结束END--
本文标题: php 移动文件失败怎么办
本文链接: https://www.lsjlt.com/news/1041.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0