EQUEST["hDFile"]; //類型 $pSFile = $_REQUEST["hDFile"]; //檔名 (!empty($pDFile) && !empty($pSFile)) or die(""); $pFileDir = "../upfiles/tw_/"; //指定路徑 if (file_exists($pFileDir.$pDFile)) { $ext1 = substr($pDFile,-3); switch ($ext1) { case "pdf":$pType="application/pdf";break; //$pType = mime_content_type($pFileDir.$pFileName); case "exe":$pType="application/Octet-stream";break; //$pType = "Application/Octet-stream"; case "zip":$pType="application/zip";break; case "doc": $pType="application/msword";break; case "xls": $pType="application/vnd.ms-excel"; break; case "ppt": $pType="application/vnd.ms-powerpoint"; break; case "gif": $ptype="image/gif"; break; case "png": $ptype="image/png"; break; case "jpg": $ptype="image/jpg"; break; default: //當然最後預防有心人士下載php或是其它我們不想讓別人下載的檔案 //所以除了我們指定可以下載的檔,其它一律不準下載 echo "You can't download this file!"; exit; } $pFile = @fopen($pFileDir.$pDFile,"rb"); $pSize = @filesize($pFileDir.$pDFile); $pContent = @fread($pFile,$pSize); @fclose($pFile); //header("Content-type:$pType"); header("Content-type: application/octet-stream"); header("Content-Disposition:attachment;filename=".basename($pSFile)); header("Content-length:$pSize"); header("Content-Transfer-Encoding:binary"); header("Pragma:no-cache"); echo($pContent); flush(); } else { echo ""; exit; } ?>