【问题标题】:Failed to open stream when uploading file via ajax通过ajax上传文件时无法打开流
【发布时间】:2019-05-26 04:44:35
【问题描述】:

我在生产 DigitalOcean VPS 中使用 ubuntu 和 LEMP 有一个 laravel 应用程序,网络运行良好,但似乎我无法从我的网络上传文件,当我尝试通过 ajax 上传图像时出现以下错误(仅在生产中,本地工作正确):

message fopen(/var/www/luisaldada.com/public/uploads/file-25-05-2019-21-39-MAL-421.jpeg): failed to open stream: Permission denied
exception   ErrorException
file    /var/www/luisaldada.com/vendor/league/flysystem/src/Adapter/Local.php
line    158

这看起来像是一个明显的权限错误,但我已经递归地给了 laravel 存储文件夹写权限,我正在使用 laravel 公共/本地磁盘将文件上传到公共内部的上传文件夹中。

文件系统配置文件:

'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

也许这与公用文件夹没有正确的上传/写入权限有关?

这是我对 laravel 文件夹的权限,你可以看到我已经为存储文件夹设置了 ACL。

https://i.imgur.com/LLYIECc.png

这是我在控制器中上传文件的方式,以防万一:

$file = $request->file($name);
        $filename = 'file-'.Carbon::now()->format('d-m-Y-H-i').'-'.str_random(3).'-'.mt_rand('000','999').'.'.$file->extension();
        $file->storeAs('uploads', $filename);

【问题讨论】:

  • 错误消息似乎表明您正在尝试保存到 uploads 文件夹,而不是 storage 文件夹。

标签: php laravel ubuntu


【解决方案1】:

好的,在检查了 public 中的上传文件夹权限后,它们是:rwx r-x --x,我做了一个 chmod 770 来上传,现在一切正常,你们怎么看,我希望我没有做任何冒险的事情。

我想向你们展示我现在使用 fot 设置烫发的命令,以便你们给我一些想法:

cd /var/www/luisaldada.com
sudo chown GabotronES:ww-data /var/www/luisaldada.com
&&
find /var/www/luisaldada.com -type d -exec chmod 755 {} \;
&&
find /var/www/luisaldada.com -type f -exec chmod 644 {} \;
&&
chmod 770 /var/www/luisaldada.com/public/uploads
&&
setfacl -Rdm u:www-data:rwx,u:GabotronES:rwx storage bootstrap/cache
&&
setfacl -Rm u:www-data:rwx,u:GabotronES:rwx storage bootstrap/cache

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多