"未找到此文件。", "1"=>"不允许下载此类文件." ); var $message_EN=array( "0"=>"this file does not exit.", "1"=>"this file is deny." ); function __construct($serverPath){ $this->serverPath=$serverPath; if($this->language=="CN"){ $this->message=$this->message_CN; }else{ $this->message=$this->message_EN; } } /* 检查文件是否存在并检测是否允许下载此类型的文件 */ function get_ext($file){ $file_ext=substr($file,-4); if(!file_exists($this->serverPath."/".$file)){ $this->error("0"); } if(!in_array($file_ext,$this->allow)){ $this->error("1"); } } function down($filename, $mimeType = 'application/octet-stream'){ $this->get_ext($filename); $fullname=$this->serverPath."/".$filename; header("Content-Type: {$mimeType}"); $filename = '"' . htmlspecialchars($filename) . '"'; $filesize = filesize($fullname); header("Content-Disposition: attachment; filename={$filename}; charset=utf-8"); header("Content-Length: {$filesize}"); readfile($fullname); exit; } function error($i){ $error="
".$this->message[$i]."
"; die($error); exit; } /* end of class */ } ?>