'mime type' // If myme type is set to empty string then script will try to detect mime type // itself, which would only work if you have Mimetype or Fileinfo extensions // installed on server. $allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // executables 'exe' => 'application/octet-stream', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', // audio 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', // video 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo' ); $file = str_replace(array('../'), '', $file); if ( file_exists("file/".$file) && is_file("file/".$file) ) { set_time_limit(0); $insertDownloadSQL = "INSERT INTO `".$sysDbPrefix."_download` (`download_datetime` ,`download_ip` ,`download_path`)VALUES (NOW(), '".$_SERVER['REMOTE_ADDR']."', '".$file."');"; $insertDownloadResult = sysDbResult($insertDownloadSQL); $filename = substr($file, strrpos($file,'/')+1,strlen($file)-strrpos($file,'/')); // file extension $fext = strtolower(substr(strrchr($filename,"."),1)); // get mime type if ($allowed_ext[$fext] == '' || array_key_exists($fext, $allowed_ext)) { $mtype = ''; // mime type is not set, get from server settings if (function_exists('mime_content_type')) { $mtype = mime_content_type("file/".$file); } else if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); // return mime type $mtype = finfo_file($finfo, "file/".$file); finfo_close($finfo); } if ($mtype == '') { $mtype = "application/force-download"; } } else { $mtype = "application/force-download"; } header("Content-Type: $mtype"); header("Content-Transfer-Encoding: Binary"); $filename = str_replace(array('"',"'",'\\','/',' '), '_', $filename); header( "Content-Disposition: attachment; filename=".$filename ); header( "Content-Length: ".filesize("file/".$file) ); readfile( "file/".$file ); die(); } else { sysDie("下載錯誤
找不到檔案","AGC-D:".$file,__FILE__); } ?> 基督教宣道會廣恩堂 | 首頁