Page 1 of 1

launching a pdf <SOLVED>

Posted: Fri Oct 19, 2007 8:55 am
by PastorHank
I'm trying to launch a pdf file that's listed in my database - file is pure php no html involved

Code: Select all

$row = mysql_fetch_array($result1);
    extract($row);
   
	$firstpart="Location: http://www.whathesees.net";
	$folderforfile="/stories/";
	$filetoshow=$firstpart.$folderforfile.$nameofnote;

/* using var_dump to insure correct file name */
              var_dump($filetoshow);
/* var_dump returns --- correct path and file - string(60) "Location: http://www.whathesees.net/stories/sakeleavesus.pdf"  */

	header('Content-type: application/pdf');
	header($filetoshow)
	exit;
If I paste what var_dump returns in my browser it pulls up the correct pdf file. Have I left out something for the Header function?

TIA

Posted: Fri Oct 19, 2007 9:52 am
by PastorHank
Commented out the var_dump
changed exit;
to exit();

It now works

Posted: Fri Oct 19, 2007 12:35 pm
by andym01480
The reason why commenting out var_dump was needed is that it sends "headers" to the browser and so you cannot then resend headers!

I've found that sending pdf's to browsers can be a bit hit and miss with IE - sometimes it spews the pdf code rather than the document particularly if refresh is pressed, so I use

Code: Select all

header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=$filetoshow");
header("Content-Transfer-Encoding: binary");
readfile("$filetoshow");
which gives people the option of opening or saving too!

Posted: Fri Oct 19, 2007 1:15 pm
by PastorHank
Thanks for the tip. I'm going to play with it some more....while testing various combinations, I did discover the joy of watching the browser window fill up with basically a bunch of garbage.....

So many variations, so little time......