777文件夹上的move_uploaded_file权限被拒绝

时间:2014-06-20 16:38:14

标签: php laravel upload

以下是我尝试通过ajax上传时收到的错误:

move_uploaded_file(/public/assets/uploads/photodune-5351272-asian-traditional-bell-l.jpg): failed to open stream: Permission denied

我的上传文件夹已使用chmod设置为777。这是我的文件夹的状态:

drwxrwxrwx 2 ec2-user ec2-user 4096 Jun 20 10:46 uploads

以下是我在PHP方面使用的代码:

if (Input::hasFile('file')) {

    $storeFolder = '/assets/uploads/';

    if (!empty($_FILES)) {
        $tempFile = $_FILES['file']['tmp_name'];
        $targetPath = public_path() . $storeFolder;
        $targetFile =  $targetPath. $_FILES['file']['name'];
        move_uploaded_file($tempFile, $targetFile);

        echo $targetPath . " / " . $targetFile;
    }

} else {
    echo "There has been an error in creating the file";
}

为什么我在尝试使用move_uploaded_file时仍然会获得权限被拒绝?

为了测试,您可以在此处查看fileupload和错误:http://www.relatient.net/relatientv2/public/portal/upload

1 个答案:

答案 0 :(得分:0)

由于某种原因,assets文件夹也需要设置为775,而laravel本身必须这样做:./ composer.phar dumpautoload。

完成此操作后,一切正常上传。