1273660434/P1.pdf _tpl_vars['dfile']; ?> "; //echo "===".$file_name."==="; if(isset($file_name)) { // echo "Filename set
"; // echo "/download_files/".$file_name."
"; if(file_exists($bdir."patent_files/".$file_name)) { // echo "Download File
"; dl_file($bdir."patent_files/".$file_name); } } function dl_file($file){ if (!is_file($file)) { die("404 File not found!"); } $len = filesize($file); $filename = basename($file); $fileinfo = pathinfo($file); $file_extension = $fileinfo['extension']; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; case "mp3": $ctype="audio/mpeg"; break; case "wav": $ctype="audio/x-wav"; break; case "mpeg": case "mpg": case "mpe": $ctype="video/mpeg"; break; case "mov": $ctype="video/quicktime"; break; case "avi": $ctype="video/x-msvideo"; break; //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files) case "php": case "htm": case "html": case "txt": die("Cannot be used for ". $file_extension ." files!"); break; default: $ctype="application/force-download"; } ob_clean(); //Begin writing headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); //Use the switch-generated Content-Type // header("Charset=UTF-8"); header("Content-Type: $ctype"); //header('Content-Transfer-Encoding: none'); //Force the download $header="Content-Disposition: attachment; filename=".$filename.";"; header($header ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$len); ob_end_flush(); // stop output buffering. Otherwise, large file will overflow output buffer by readfile @readfile($file); } ?>