note 38736 deleted from function.header by victor

From: Date: Sat, 19 Jun 2004 15:40:02 +0000
Subject: note 38736 deleted from function.header by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71362@lists.php.net to get a copy of this message
Note Submitter: ergon@wanadoo.es ---- Other alternative script proposed for downloading files of various types. -- download.php -- <? $filename = $_GET['file']; $ext = substr( $filename,-3 ); if( $filename == "" ) { echo "<html><body>ERROR: Empty file to download. USE download.php?file=[file path]</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><body>ERROR: File not found. USE download.php?file=[file path]</body></html>"; exit; }; switch( $ext ){ 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 "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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"]); if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) { header( "Content-Disposition: filename=".basename($filename).";" ); } else { header( "Content-Disposition: attachment; filename=".basename($filename).";" ); } header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> -- eof --

« previous php.notes (#71362) next »