samedi 30 juin 2018

Laravel, trying to use helper to display PDF

I'm trying to display a PDF file I have in my storage\reports folder inline in the browser.

My file is: storage\reports\Real_Estate_Test.pdf

I have a helper file: app\Helpers\helpers.php

I call the PDF from my blade with:

where

$filepath = storage_path().'\reports';
$ext = "pdf";
$filename = "Real_Estate_Test";

In my helper file I have:

<?php

use Response;

if (! function_exists('viewReport')) 
{
    function viewReport($filepath, $ext, $filename)
    {
$filename.".".$ext, [], 'inline');

        $headers = [
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'inline; ' . $filepath."\\".$filename.".".$ext,
        ];

        return Response::make(File::get($filepath."\\".$filename.".".$ext), 200, $headers);

    }
}

In my composer.json I have:

 "autoload": {
    "classmap": [
      "database"
    ],
    "psr-4": {
      "App\\": "app/"
    },
    "files": [
      "app/Helpers/helpers.php"
    ]
  },

I get this error at the top of my page:

Warning: The use statement with non-compound name 'Response' has no effect in C:\xampp\htdocs\DS_dev_01\app\Helpers\helpers.php on line 4

where line 4 is use Response;

If I comment out line 4 I then get nothing.

I've also tried doing this with this suggestion from another post:

return response()->download($filepath."\\".$filename.".".$ext, $filename.".".$ext, [], 'inline');

and I get the following string displayed at the top of my page (no PDF):

HTTP/1.0 200 OK Cache-Control: public Content-Disposition: inline; filename="Real_Estate_Test.pdf" Date: Sat, 30 Jun 2018 18:21:48 GMT Last-Modified: Sat, 30 Jun 2018 18:21:48 GMT

which looks really close to a command to load and display my PDF.

Any suggestions as to what I'm doing wrong. Trying to piece together hints from Laravel docs and many posts is not getting me anywhere.

I'm running Laravel 5.5 on XAMPP in Win10 with PHP7

Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2tR3g5K
via IFTTT

Aucun commentaire:

Enregistrer un commentaire