Copy CodeThe code is as follows:
$file = ' monkey.gif ';
if (file_exists ($file)) {
Header (' Content-description:file Transfer ');
Header (' Content-type:application/octet-stream ');
Header (' content-disposition:attachment; Filename= '. basename ($file));
Header (' content-transfer-encoding:binary ');
Header (' expires:0 ');
Header (' Cache-control:must-revalidate, post-check=0, pre-check=0 ');
Header (' Pragma:public ');
Header (' Content-length: '. FileSize ($file));
Ob_clean ();
Flush ();
ReadFile ($file);
Exit
}
?>
The above code is the download code
Next, post a code to preview the pdf file online.
Copy CodeThe code is as follows:
Public Function fddaction ()
{
Get Attachment Location
$attachment _location = $_server["Document_root"]. "/pdf/fdd/sample.pdf";
if (file_exists ($attachment _location)) {
Attachment exists
Send open PDF dialog to user
Header (' Cache-control:public '); needed for i.e.
Header (' content-type:application/pdf ');
Header (' Content-disposition:inline; filename= ' sample.pdf ');
ReadFile ($attachment _location);
Die (); Stop execution of further script because we is only outputting the PDF
} else {
Die (' error:file not found. ');
}
}
?>
http://www.bkjia.com/PHPjc/325507.html www.bkjia.com true http://www.bkjia.com/PHPjc/325507.html techarticle Copy the code as follows: PHP $file = ' monkey.gif ', if (file_exists ($file)) {header (' content-description:file Transfer '); Header (' Content-type:application/octet-stream '); Head ...