[PHP] header下載檔案 搭配資料庫
剛剛在 ECstart 看到有人詢問 header檔案下載錯誤 發現網站義工有回答到這個function,所以就紀錄下來了
function dl_file($file){
//First, see if the file exists
if (!is_file($file)) { die("404 File not found!"); }
//Gather relevent info about file
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
//This will set the Content-Type to the appropriate setting for the file
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 "
[Read More]