<?
$filename = $_GET['file'];

$ext = substr(strrchr($filename,"."), 1);

if( $filename == ""){
	echo "<html><body>Cannot find this file!!!</body></html>";
	exit;
}elseif(!file_exists($filename)) {
	echo "<html><body>Cannot find this file!!!</body></html>";
	exit;
}

switch(strtolower($ext)){
	case "pdf": $ctype="application/pdf"; break;
	case "exe": $ctype="application/octet-stream"; break;
	case "zip": $ctype="application/zip"; break;
	case "rar": $ctype="application/rar"; break;
	case "mp3": $ctype="application/mp3"; break;
	case "iso": $ctype="application/iso"; break;
	case "doc": $ctype="application/msword"; break;
	case "xls": $ctype="application/vnd.ms-excel"; break;
	case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
	case "php": $ctype="application/Notepad"; break;
	case "xml": $ctype="application/xml"; break;
	case "xhtml": $ctype="application/xhtml"; break;
	case "html": $ctype="application/html"; break;
	case "gif": $ctype="image/gif"; break;
	case "png": $ctype="image/png"; break;
	case "jpg": $ctype="image/jpg"; break;
	case "jpeg": $ctype="image/jpeg"; break;
	default: 
		$ctype="application/txt"; break;
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: $ctype");
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename)); 

$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
print ($contents);
flush();
?>
