path; $filename = "./upload/".$show->path; /* 也可以在這裡可以加上路徑,如改為 $filename = "/download/".$_GET['file']; */ $ext = substr($filename,-3 ); $ext = strtolower($ext); //echo $filename; if( $filename == "" ) { echo "未指定檔案路徑及名稱!"; exit; } elseif ( ! file_exists( $filename ) ) { echo "找不到檔案!"; exit; }; switch( $ext ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "doc": $ctype="application/msword"; break; case "docx": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "xlsx": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "pptx": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpg": $ctype="image/jpg"; break; case "txt": $ctyp="text/plain"; break; default: echo "您不可以下載這個檔案!"; exit; } 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(); ?>