move_uploaded_file()无法将文件从tmp移动到dir

  发布于 2023-02-04 17:58

我一直在寻找解决方案,但我找不到答案.

我创建了一个图片上传表单.它使用ajaxform插件运行.但它仍然没有上传到目录.error_log说

move_uploaded_file()无法将文件从[tmp]移动到[dir].

然后在前端显示上传完成.但是当调用文件时,它不存在.

HTML代码:


JS:

var options = { 
    beforeSend: function() 
    {
        $(".imguploadProgress").show();
        $(".imguploadProgressBar").width('0%');
        $(".imguploadMsg").html("");
        $(".imguploadProgressPercent").html("0%");
    },
    uploadProgress: function(event, position, total, percentComplete) 
    {
        $(".imguploadProgressBar").width(percentComplete+'%');
        $(".imguploadProgressPercent").html(percentComplete+'%');

    },
    success: function() 
    {
        $(".imguploadProgressBar").width('100%');
        $(".imguploadProgressPercent").html('100%');

    },
    complete: function(response) 
    {
        alert('Complecion');
    },
    error: function()
    {
        $(".imguploadMsg").html(" ERROR: unable to upload files");
    }

    }; 

     $("#profpicform").ajaxForm(options);

SEVER SIDE:

$output_dir = home_url()."/path/to/dir/";

if(isset($_FILES["profpic"])){
    if ($_FILES["profpic"]["error"] > 0){
      echo "Error: " . $_FILES["file"]["error"] . "
"; }else{ move_uploaded_file($_FILES["profpic"]["tmp_name"],$output_dir. $_FILES["profpic"]["name"]); if(get_user_meta($_SESSION['userid'], 'user_profile_picture')==""){ add_user_meta($_SESSION['userid'], 'user_profile_picture', $_FILES['profpic']); }else{ update_user_meta($_SESSION['userid'], 'user_profile_picture', $_FILES['profpic']); } echo "Uploaded File :".$_FILES["profpic"]["name"]; } }

它们只能在一个PHP文件中找到.该目录的文件夹权限是777.

1 个回答
  • 试试这个:

    $destination_path = getcwd().DIRECTORY_SEPARATOR;
    $target_path = $destination_path . basename( $_FILES["profpic"]["name"]);
    @move_uploaded_file($_FILES['profpic']['tmp_name'], $target_path)
    

    2023-02-04 17:59 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有