mkdir():权限被拒绝Laravel [英] mkdir(): Permission denied Laravel

查看:1035
本文介绍了mkdir():权限被拒绝Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为服务器中的图像上载运行以下脚本,并在以下主机上正常运行时收到以下错误.

I'm running the following script for an image upload in a server and getting the following error while it works perfectly on the localhost.

代码

$user_id = Auth::id();
$logicpath = 'userdp/' . $user_id . '/';
$pubpath = 'userdp/' . $user_id . '/' . $dpFile;
$path = '/userdp/' . $user_id . '/' . $dpFile;

if (!file_exists($logicpath)) {
     mkdir($logicpath, 0777, true);
}

错误

UploadController.php第605行中的ErrorException:mkdir():权限 拒绝

ErrorException in UploadController.php line 605: mkdir(): Permission denied

在HandleExceptions-> handleError('2','mkdir():权限被拒绝', '/var/www/html/laravel/app/Http/Controllers/UploadController.php', '605',array('dp'=> object(UploadedFile),'ext'=>'jpg','img'=> object(Image),'mime'=>'image/jpeg','width'=>'200','height'=> '200','fileSize'=>'17152','dpFile'=> 'f12f298ab18d58a59c4ed8a589cd1cdc.jpg','user_id'=>'1','logicpath' =>'userdp/1/','pubpath'=>'userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg','path'=> '/userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg'))

at HandleExceptions->handleError('2', 'mkdir(): Permission denied', '/var/www/html/laravel/app/Http/Controllers/UploadController.php', '605', array('dp' => object(UploadedFile), 'ext' => 'jpg', 'img' => object(Image), 'mime' => 'image/jpeg', 'width' => '200', 'height' => '200', 'fileSize' => '17152', 'dpFile' => 'f12f298ab18d58a59c4ed8a589cd1cdc.jpg', 'user_id' => '1', 'logicpath' => 'userdp/1/', 'pubpath' => 'userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg', 'path' => '/userdp/1/f12f298ab18d58a59c4ed8a589cd1cdc.jpg'))

我尝试了chmod 777 public并重新启动了服务器.但这没有用.

I tried chmod 777 public and restarted the server. But it didn't work.

推荐答案

您必须递归执行chmod,以确保所有子目录也都具有相同的权限.尝试运行此代码:

You have to perform chmod recursively to make sure all subdirectories also carry the same permissions. Try running this instead:

chmod -R 777 

现在,尽管这可以解决您的问题,但您绝对应该阅读设置以上权限所引起的问题,如下面评论中发布的此链接所示.病也张贴在这里:

Now while this will fix your issue, you should definitely read up on the problems that arise with setting the above permissions as this link posted in comments below shows. Ill post here as well:

http://stackoverflow.com/a/11271632/2790481

例如,仅应在/var/www/html/laravel/storage中的Laravel存储目录中完成此操作,而切勿在系统级别执行此操作.我最初忘了提到这一点,因此忘记了所有的反对意见.

This should only be done within the Laravel storage dir within /var/www/html/laravel/storage, for example and never be done at the system level. I forgot to mentioned that originally, hence all the downvotes.

这篇关于mkdir():权限被拒绝Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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