Last active
January 16, 2017 01:08
-
-
Save toddnestor/dd9c3c9a3cbbf221519c0838a97d4540 to your computer and use it in GitHub Desktop.
This file contains 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 | |
function forceDownload() | |
{ | |
$file_name = "/some/directory/not/publicly/available/" . $_GET['file']; | |
$file = file_get_contents( $file_name ); | |
if( !empty($file) ) | |
{ | |
header( 'Content-Description: File Transfer' ); | |
header( 'Content-Type: application/octet-stream' ); | |
header( 'Content-Disposition: attachment; filename=' . $_GET['file'] ); | |
header( 'Content-Transfer-Encoding: binary' ); | |
header( 'Connection: Keep-Alive' ); | |
header( 'Expires: 0' ); | |
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); | |
header( 'Pragma: public' ); | |
header( 'Content-Length: ' . filesize( $file_name ) ); | |
echo $file; | |
exit; | |
} | |
} | |
function authenticate() | |
{ | |
//do authentication stuff and return true if authenticated, false otherwise | |
} | |
if( authenticate() ) | |
{ | |
forceDownload(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment