laravel mkdir()权限被拒绝

时间:2015-11-22 22:25:41

标签: php laravel-5

我尝试使用以下方法创建一个包含子目录的文件夹(如果它尚不存在):

public function createFolderIfNotExist($path){
    //Check if the folder already exists
    if(!File::Exists($path)){
        //make folder with $path generate recursive with right 0775
        File::makeDirectory($path, 0775 , true);
    }
}

运行localy时工作正常(xampp),当推送到服务器时返回

  

许可被拒绝

错误的第一行

  在Filesystem.php第337行

     

at HandleExceptions-> handleError('2',   'mkdir():权限被拒绝',   '/var/www/****/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',   '337',数组('path'=>   '/ var / www / **** / public / images \ product \ 206','mode'=>   '509','递归'=>是的,'force'=>假))

     

在   mkdir('/ var / www / **** / public / images \ product \ 206','509',   true)在Filesystem.php第337行

     

在   所在文件系统> makeDirectory( '/无功/网络/ **** /公共/图像\产品\ 206',   “Facade.php第216行”中的“509”,真实

     

在   门面:: __ callStatic( 'makeDirectory',   array('/ var / www / **** / public / images \ product \ 206','509',   true))在ProductController.php第452行

错误消息使其看起来像我试图将权限设置为509

我传递的路径是:

$pathThumb = public_path('images\product\\'.$product->id.'\thumb');

检查服务器上的权限时,它会显示公共文件夹的775。

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:2)

运行php服务器的unix用户无权访问$path的父目录。

Google搜索"permission denied" makeDirectory shows the same

问题出在PHP之外,因此您需要确定如何make the folder writeable like this,或者将文件放在可写入php服务器进程用户的目录中。这应该涉及您的系统管理员/ devops人员。

相关问题