Search code examples
phplaravelpdfdownloadresponse

Laravel download not work


I have a problem with Laravel 5.2 and Response::download()

My code is very simple:

file_get_contents("pathtofile/test.pdf");

works perfectly, but this:

return Response::download('pathtofile/test.pdf', 'test.pdf', [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => 'inline; ' . 'test',
]);

leaves me with:

FileNotFoundException in File.php line 37: The file "pathtofile/test.pdf" does not exist

I have a shared drive between a linux server and windows and the files are on the windows server and my site is on the linux server.


Solution

  • I find response

    header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename=$filename");
            header("Content-Type: $contentType");
            header("Content-Transfer-Encoding: binary");
            readfile($path);
    

    works