drbae3964 2019-05-07 05:22
浏览 66
已采纳

在Laravel 5.8中上传的图片一直保存为私人图片

I am trying upload a single image into a Post and it keeps saving it as a private image--heck, I don't even know where to find that file.

PostController.php

...
if ($request->hasFile('photo')) {
    $photo = $request->photo;
    $ext = $photo->getClientOriginalExtension();
    $filename = uniqid() . '.' . $ext;
    $photo->storeAs('public/posts/' . $request->user()->id, $filename);
}
...

enter image description here

  • 写回答

1条回答 默认 最新

  • duanmou9228 2019-05-07 05:37
    关注

    storeAs() function takes three parameters.

    storeAs(path,name,options)
    

    'options' is where you specify file visibility. In your case :

    if ($request->hasFile('photo')) {
        $photo = $request->photo;
        $ext = $photo->getClientOriginalExtension();
        $filename = uniqid() . '.' . $ext;
        $photo->storeAs('posts/' . $request->user()->id, $filename,'public');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码