79185108

Date: 2024-11-13 13:34:20
Score: 0.5
Natty:
Report link

I was facing the same issue, but I needed to display it directly in the user's browser rather than prompting for a download.

so here is how I handled it:

$body = Http::withHeaders(['Content-Type' => 'application/pdf'])
  ->get('https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf')
  ->body();

$headers = [
        "Content-type" => "application/pdf",
        "Content-Disposition" => "inline; filename=the-file.pdf",
        "Access-Control-Expose-Headers" => "Content-Disposition",
        "Pragma" => "no-cache",
        "Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
        "Expires" => "0"
    ];

return response()->stream(function() use($body){
        $file = fopen('php://output', 'w');
        fwrite($file, $body);
        fclose($file);
    }, 200, $headers);
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mazen Bassiouni