douchunjing6587 2019-02-11 20: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 21: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条)

报告相同问题?