Created
July 18, 2014 11:43
-
-
Save rendfall/f906f9468b9f27df2f9a to your computer and use it in GitHub Desktop.
Download file indirectly
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
if(false == isset($_GET['f'])): | |
wp_redirect($_SERVER['HTTP_REFERER']); | |
exit(); | |
endif; | |
$path = '/uploads'; | |
$path = $path. '/'. $_GET['f']; | |
$filename = $_GET['f']; | |
$mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so | |
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: " . $mm_type); | |
header("Content-Length: " .(string)(filesize($path)) ); | |
header('Content-Disposition: attachment; filename="'. $filename .'"'); | |
header("Content-Transfer-Encoding: binary\n"); | |
readfile($path); // outputs the content of the file | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment