【问题标题】:Yii will not move_uploaded_file - 500 internal server errorYii 不会移动_uploaded_file - 500 内部服务器错误
【发布时间】:2015-06-10 17:22:40
【问题描述】:

我正在使用带有 Yii 的 blueimp 文件上传插件来尝试将文件上传到我的服务器(当前为 localhost)。我给了文件夹完整的读/写权限(位置是 C:\xampp\htdocs\yii),但是当我尝试执行 move_uploaded 文件命令时仍然出现错误。

这里是主窗体和输入文件区:

<form id='upload' method='post' action='?r=site/move' enctype='multipart/form-data' style="padding:0;">
    <span class="btn fileinput-button" style="padding:0">
        <i class="glyphicon glyphicon-picture">
            <input id="fileupload" type="file" accept="image/*" name="attachment" onchange="attachAttachment()">
        </i>                                        
    </span>
</form>

这是 blueimp 的文件上传(在 function() 中):

$("#fileupload").fileupload
({

        dataType: 'json', 

        done: function (e, data) 
        {
            console.log("YAY");
        },

        fail: function(e, data)
        {
            console.log("FAIL");
        }
});

这是actionMove,我将文件从临时目录移动到文件夹:

public function actionMove()
{
    if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == 0)
    {           
        if (move_uploaded_file($_FILES['attachment'], Yii::getPathOfAlias('webroot')."/images/uploads")){ 
            $response = '{"status":"success"}';
        }
        else { 
            $response = '{"status":"error"}';
        }

        echo $response; 
        exit();
    }   
}

我已经在这几个小时了,感谢任何帮助:(

【问题讨论】:

    标签: php jquery yii blueimp


    【解决方案1】:

    $_FILES['attachment'] 引用有关下载的所有数据。 move_uploaded_file 使用文件名工作。以下是您应该尝试的方法:

    $uploadPath = Yii::getPathOfAlias('webroot')."/images/uploads";
    $uploadFilename = basename($_FILES['attachment']['name']);
    $tempFilename = $_FILES['attachment']['tmp_name'];
    $ok = move_uploaded_file($tempFilename, $uploadPath.'/'.$uploadFilename);
    if ($ok) {
        $response = '{"status":"success"}';
    } else {
        $response = '{"status":"error"}';
    }
    

    更多关于这方面的文档页面: http://php.net/manual/fr/features.file-upload.post-method.phphttp://php.net/manual/fr/function.move-uploaded-file.php

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2011-10-17
      • 2010-11-15
      相关资源
      最近更新 更多