-
-
Save muhamed-didovic/b97c35897304a6f32648 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 | |
/** | |
* Will handle downloads for $_REQUEST['file'] | |
* @author Julius Beckmann | |
*/ | |
function handleForcedDownloads($parameterName='file', $exit=true) | |
{ | |
if(isset($_REQUEST[$parameterName])) { | |
$file = $_REQUEST[$parameterName]; | |
if(false !== stripos($file, '../')) { | |
die("ERROR: Fehlerhafter Download Link."); | |
} | |
// Working on purpose with cwd. | |
if(!file_exists($file)) { | |
die("ERROR: Datei konnte nicht gefunden werden."); | |
} | |
header('Content-Type: application/octet-stream'); | |
header('Content-Transfer-Encoding: binary'); | |
header('Content-disposition: attachment; filename="'.basename($file).'"'); | |
readfile($file); | |
if($exit) { | |
die(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment