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条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行