<?php

// Initialize the file (for sceurity).
$file = "";

/* Get the name of the image (without the path) from the URL or the link*/
$file = $_REQUEST['f'];

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

if (empty($file))
        exit;

/* Don't allow hidden files (their names begin with a dot) to be downloaded */
if ($file[0] == ".")

// Initialize path
$path = "";

// Specify the directory in which the images are located.
/* You should be very careful. You should not allow the user to use any directory or any file. You should 
initialize your directory and your file, and you should not allow directories whose name begin with a period 
to be processed because that will enable the user to go backward and check all directories in the server. Also, 
you should not allow the user to access files whose names begin with a period because these are usually hidden 
files such as .htaccess files*/

$path = "/home/abu-jeib/temp2/";

// Append the path to the name of the file
$file = $path.$file;

// Now prompt the user to download the image
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
#$file = "/home/abu-jeib/proposals/abu-jeib1.html";
$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);
?>

