Created
January 2, 2017 10:25
-
-
Save rajvanshipradeep15/7dad502441ba1f24b06d55d81e7e5389 to your computer and use it in GitHub Desktop.
download pdf inline and attachment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( 1 == $_GET['file'] ) { | |
//file which we need to open in browser. | |
$filename="pdf_sample.pdf"; | |
$header="Content-Disposition: inline; filename=$filename;"; // Send File Name | |
} else { | |
//password protected file | |
$filename="pdf_sample_protected.pdf"; | |
$header="Content-Disposition: attachment; filename=$filename;"; // Send File Name | |
} | |
$file="./user_pdfs/$filename"; | |
$len = filesize($file); // Calculate File Size | |
ob_clean(); | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Cache-Control: public"); | |
header("Content-Description: File Transfer"); | |
header("Content-Type:application/pdf"); // Send type of file | |
header($header ); | |
header("Content-Transfer-Encoding: binary"); | |
header("Content-Length: ".$len); // Send File Size | |
@readfile($file); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment