move_uploaded_file()无法将文件从tmp移到dir [英] move_uploaded_file() Unable to move file from tmp to dir

查看:114
本文介绍了move_uploaded_file()无法将文件从tmp移到dir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been searching for the solution but I can't find the answer.

我创建了一张图片上传表格.它与ajaxform插件一起运行.但是它仍然不会上传到目录中. error_log说

I created a image upload form. It runs with ajaxform plugin. But still it doesn't upload to the directory. The error_log says

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

move_uploaded_file() Unable to move file from [tmp] to [dir].

然后在前端显示"Upload Complete".但是当文件被调用时,它不存在.

Then on the front end it says Upload Complete. But when the file is called, it doesn't exist.

HTML代码:

<div class="imgupload hidden">  
    <form id="profpicform" action="" method="post" enctype="multipart/form-data">
        <input type="file" size="60" name="profpic">
        <input type="submit" value="Submit File">
    </form>

    <div class="imguploadStatus">
        <div class="imguploadProgress">
            <div class="imguploadProgressBar"></div>
            <div class="imguploadProgressPercent">0%</div>
        </div>
        <div class="imguploadMsg"></div>
    </div>
    <div class="imgpreview"></div>
</div>

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("<font color='red'> ERROR: unable to upload files</font>");
    }

    }; 

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

服务器端

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

if(isset($_FILES["profpic"])){
    if ($_FILES["profpic"]["error"] > 0){
      echo "Error: " . $_FILES["file"]["error"] . "<br>";
    }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.

They are only found in one PHP file. Folder permission for the directory is 777.

推荐答案

尝试一下:

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

这篇关于move_uploaded_file()无法将文件从tmp移到dir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆