back to devpro   download
function forceDownload($file) {
	/**
	 * Function forceDownload:
	 *	download any type of file if it exists and is readable
	 * -------------------------------------
	 * @author		Andrea Giammarchi
	 * @date		18/01/2005 [17/05/2006]
	 * @compatibility	PHP >= 4.3.0
	 */
	if(file_exists($file) && is_readable($file)) {
		$filename = basename($file);
		if(strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !== false && strpos($filename, '.') !== false) {
			$parsename = explode('.', $filename);
			$last = count($parsename) - 1;
			$filename = implode('%2E', array_slice($parsename, 0, $last));
			$filename .= '.'.$parsename[$last];
		}
		header('Content-Type: application/octet-stream');
		header('Content-Disposition: attachment; filename="'.$filename.'"');
		header('Content-Length:'.filesize($file));
		header('Content-Transfer-Encoding: binary');
		if(@$file = fopen($file, "rb")) {
			while(!feof($file))
				echo fread($file, 8192);
			fclose($file);
		}
		exit(0);
	}
}
back to devpro   download
Creative Commons License