douchunjing6587 2019-02-11 12:01
浏览 46
已采纳

Laravel 5.7上传到公共文件夹不起作用

I'm trying to upload images to the storage/app/public/ folder that is linked to the public folder from Laravel. My filesystems.php is configured this way:

'default' => env('FILESYSTEM_DRIVER', 'public')
//rest of the code
        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

And at my controller, I upload the image:

$file = $request->hasFile('imagem');
$file = $request->file('imagem')->isValid();

$upload = $request->imagem->store('instituicoes');

I want the file to be uploaded to this path storage/app/public/instituicoes but when I use this code Laravel creates the 'instituicoes' folder at the storage/app folder, not at the storage/app/public/ that I defined as storage path. Laravel Folders

  • 写回答

2条回答 默认 最新

  • dongyi8416 2019-02-11 13:43
    关注

    Since your default disk is using the FILESYSTEM_DRIVER environment variable, make sure that the value of the variable is set to public as your default disk. It looks like it might be using your local disk instead.

    You could also try changing this:

    $upload = $request->imagem->store('instituicoes');
    

    to this:

    $upload = $request->imagem->store('instituicoes', 'public');
    

    to force using the public disk instead of whatever the default is.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部