Organizational Research By

Surprising Reserch Topic

using header to rewrite filename in url for dynamic pdf using -'php,pdf,mod-rewrite,rename,http-headers'

using header to rewrite filename in url for dynamic pdf  using -'php,pdf,mod-rewrite,rename,http-headers'

I have a php script that generates a pdf report. When we go to save the pdf document, the filename that Acrobat suggests is report_pdf, since the php script is named report_pdf.php. I would like to dynamically name the pdf file, so I don't have to type the appropriate name for the report each time that I save it.

Asking on a news group, someone suggested this, where filename="July Report.pdf" is the intended name of the report

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

But it doesn't work. Am I doing it wrong, or will this work at all? Is this a job for mod_rewrite?

So I've tried both

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


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

( not at the same time ) and neither work for me. Is this a problem with my web host? For this url, here's my code:

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

// requires the R&OS pdf class

// make a new pdf object
$pdf = new Cpdf();
// select the font
$pdf->addText(30,400,30,'Hello World');



asked Sep 8, 2015 by rajesh
0 votes

Related Hot Questions

2 Answers

0 votes
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.
answered Sep 8, 2015 by rajesh
0 votes
Based on (Page 21) 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.
answered Sep 8, 2015 by rajesh