Created
February 21, 2017 09:08
-
-
Save erlangparasu/b1fcf57d9a002afae9084b70ed311015 to your computer and use it in GitHub Desktop.
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 | |
// | |
$filepath = 'file.txt'; | |
/** | |
"htm" => "text/html", | |
"exe" => "application/octet-stream", | |
"zip" => "application/zip", | |
"doc" => "application/msword", | |
"jpg" => "image/jpg", | |
"php" => "text/plain", | |
"xls" => "application/vnd.ms-excel", | |
"ppt" => "application/vnd.ms-powerpoint", | |
"gif" => "image/gif", | |
"pdf" => "application/pdf", | |
"txt" => "text/plain", | |
"html"=> "text/html", | |
"png" => "image/png", | |
"jpeg"=> "image/jpg" | |
*/ | |
$finfo = finfo_open(FILEINFO_MIME_TYPE); | |
header('content-type:' . finfo_file($finfo, $filepath)); | |
// exe --> binary | |
$finfo = finfo_open(FILEINFO_MIME_ENCODING); | |
header('content-transfer-encoding:' . finfo_file($finfo, $filepath)); | |
// | |
header('content-disposition:attachment;filename="' . basename($filepath) . '"'); | |
// | |
readfile($filepath); | |
// | |
exit(); | |
// ref: | |
// http://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment