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.

    点赞 打赏 评论
  • dptpn06684 2019-02-11 21:40

    From https://laravel.com/docs/5.7/filesystem

    The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public.

    To create the symbolic link, you may use the storage:link Artisan command:

    php artisan storage:link

    点赞 打赏 评论

相关推荐 更多相似问题