using header() to rewrite filename in URL for dynamic pdf using header() to rewrite filename in URL for dynamic pdf php php

using header() to rewrite filename in URL for dynamic pdf


Try:

header('Content-Disposition: attachment; filename="July Report.pdf"');

or

header('Content-Disposition: inline; filename="July Report.pdf"');

Another option would be to use the $_SERVER['PATH_INFO'] to pass your "July Report.pdf" - an example link might be:

<a href="report_pdf.php/July%20Report.pdf?month=07">

That file should default to saving as "July Report.pdf" - and should behave exactly like your old php script did, just change the code that produces the link to the pdf.


Should be:

header('Content-disposition: attachment;filename="July Report.pdf"'); 


Based on https://github.com/rospdf/pdf-php/raw/master/readme.pdf (Page 19)The stream-method accepts an array as parameter:

stream([array options]) Used for output, this will set the required headers and output the pdf code. The options array can be used to set a number of things about the output:

'Content-Disposition'=>'filename' sets the filename, ...

This code works well for me

$ezOutput = $pdf->ezStream(array("Content-Disposition"=>"YourFileName.pdf"));

In my case I use ezStream() but I think stream() should give the same result.