无法打开流:Laravel 5.4 中的权限被拒绝,甚至在 Laravel 5.4 中使用 Store 函数将 Al 文件权限授予路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44918594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:15:47  来源:igfitidea点击:

Failed to open stream: Permission denied in Laravel 5.4 Even Al File Permission are granted to the path using Store Function in Laravel 5.4

phplaravel

提问by Sandeep Garapati

I am trying to upload a file into C:\Users\sandeep\maxo\storage\app\public folder in laravel 5.4. I am using the below code

我正在尝试将文件上传到 Laravel 5.4 中的 C:\Users\sandeep\maxo\storage\app\public 文件夹中。我正在使用下面的代码

    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
        </head>
        <body>
            <form  action="{{ URL::to('importExcelFile') }}" class="form-horizontal" method="post" enctype="multipart/form-data">
                <input type="file" name="import_file" />
                {{ csrf_field() }}
                <br/>
                <button >Import CSV or Excel File</button>
            </form>
        </body>
    </html>

$path = $request->file('import_file')->store('public');

$path = $request->file('import_file')->store('public');

is the laravel code.

是 Laravel 代码。

But I am getting an error like this

但我收到这样的错误

fopen(C:\Users\sandeep\maxo\storage\app\public/K4oIHMXveyx2VChmAXAcNkTmoIXKACvqoIbbHCeB.): failed to open stream: Permission denied

fopen(C:\Users\sandeep\maxo\storage\app\public/K4oIHMXveyx2VChmAXAcNkTmoIXKACvqoIbbHCeB.):无法打开流:权限被拒绝

This is the picture of my error Click here

这是我的错误图片 点击这里

But When i Upload the image its working fine

但是当我上传图像时它工作正常

采纳答案by shendoma03

Try on terminal sudo chmod -R 777 publicit will change the directory permission

尝试在终端上sudo chmod -R 777 public它将更改目录权限

回答by Muhammad Ibnuh

As has been stated everywhere, you better not give 777permissions, its a security risk. Instead just use

正如到处都说的那样,你最好不要授予777权限,这是一个安全风险。而只是使用

sudo chown -R www-data:www-data storage

须藤 chown -R www-data:www-data 存储

if you are using apache, it will give permission to the apache's user

如果您使用的是 apache,它将授予 apache 用户的权限