PHP Snippet 1:
<?php
$fileId = $_GET['fileId'];
switch($fileId){
case 1:
$fileName = 'myFile.pdf';
break;
case 2:
$fileName = 'myOtherFile.doc';
break;
default:
$fileName = null;
}
if($fileName){
// $fileName is your file identifier
$fileFullPath = $_SERVER['DOCUMENT_ROOT'].'mySecretFolder/files/'.$fileName;
if (file_exists($fileFullPath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fileFullPath));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($fileFullPath));
ob_clean();
flush();
readfile($fileFullPath);
exit;
}
}
?>