<?php
# How to download a file whose name and signal to which directory the file 
# is in are passed by a URL or SSI command, or by another way?
#ob_start();

$file = $_GET['f'];
$dir = $_GET['d'];

$which_directory = stripslashes(trim($dir));
$file = stripslashes(trim($file));

if (empty($file))
        exit;
if ($file[0] == ".")
        exit;

if ($which_directory == "prop")
        $path = "/home/abu-jeib/proposals/";
else if ($which_directory == "final")
        $path = "/home/abu-jeib/proposals/final_proposals/";
else
        exit;

$file = $path.$file;

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
$size = filesize($file);
$file_name = basename($file); 
# string basename(string path): Returns the file name component of path
# string dirname(string path): Returns the directory name component of path
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file_name");
header("Accept-Ranges: bytes");
header("Content-Length: $size");
@readfile($file);
#ob_end_clean();
?>
