Skip navigation

how to send down a pdf file from php without having the browser open it

instead of

header(“Content-type: application/pdf”);


# assuming your pdf doc is in the variable $pdf
$buf = pdf_get_buffer($pdf);
$dataSize = strlen($buf);
header(“Expires: 0”);
header(“Pragma: public”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Accept-Ranges: bytes”);
header(“Content-Description: File Transfer”);

header(“Content-Type: application/pdf”);
#header(“Content-type: application/octet-stream”); #try this too

header(“Content-Transfer-Encoding: Binary”);
header(“Content-Length: $dataSize”); #compute data size
header(“Content-Disposition: attachment; filename=\”whatever.pdf\””);

the browser won’t think it knows how to open it and the plug-in behavior won’t be activated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: