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');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?