Laravel - display a PDF file in storage without forcing download?

后端 未结 10 1036
陌清茗
陌清茗 2020-12-02 10:31

I have a PDF file stored in app/storage/, and I want authenticated users to be able to view this file. I know that I can make them download it using

return          


        
10条回答
  •  时光说笑
    2020-12-02 11:12

    Ben Swinburne answer was so helpful.

    The code below is for those who have their PDF file in database like me.

    $pdf = DB::table('exportfiles')->select('pdf')->where('user_id', $user_id)->first();
    
    return Response::make(base64_decode( $pdf->pdf), 200, [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; filename="'.$filename.'"',
    ]);
    

    Where $pdf->pdf is the file column in database.

提交回复
热议问题