dousi6192 2015-09-07 16:54
浏览 589
已采纳

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.

Code

$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);
}

Error

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

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'))

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

  • 写回答

6条回答 默认 最新

  • dongzhan5943 2015-09-07 16:59
    关注

    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

    EDIT: 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗