<?
	/**
	 * File downloading script.
	 *
	 * @author	$Author: suraj $
	 * @version	$Revision: 1.5 $, $Date: 2003/02/11 03:53:38 $
	 */
	//
	
	require_once("assets/includes/config.inc.php");
	
	// check if path was set
	if($path == "")
	{
		die("No file specified for download. Try again.");
	}
	
	// check for path beyond top-most allowed directory
	if(!strstr($path, realpath($cfgVars['BROWSER_ROOT_PATH'])))
	{
		die("The file you have requested is beyond the root folder.");
	}
	
	// boolean to check if the path is ready to be read from
	$path_ok = file_exists($path) && !is_dir($path) && is_readable($path);
	
	
	// start of script
	
	if($path_ok)
	{
		// send user a header to download the file
		header ("Content-Type: application/octet-stream");
		header ("Content-Length: ".filesize($path));
		header ("Content-Disposition: attachment; filename=". basename($path));

		readfile($path); // "read" the data to the user's browser where they can now download it
	}
	else
	{
		die("Unable to access file <tt>$path</tt> for downloading.");
	}
?>
