Php sample code for downloading files. Copy the code as follows :? Php?filemonkey.gif; if (file_exists ($ file) {header (Content-Description: FileTransfer); header (Content-Type: applicationoctet-stream); head
The 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, paste the code for previewing PDF files online.
The 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 are only outputting the pdf
} Else {
Die ('Error: File not found .');
}
}
?>
The http://www.bkjia.com/PHPjc/325507.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325507.htmlTechArticle code is as follows :? Php $ file = 'monkey.gif '; if (file_exists ($ file) {header ('content-Description: File Transfer'); header ('content-Type: application/octet-stream '); head...