check_file_ext($file_name); $this->check_file_exists($full_file_name); header("Content-Type: {$mime_type}"); $file_name = '"' . htmlspecialchars($file_name) . '"'; $file_size = filesize($full_file_name); header("Content-Disposition: attachment; filename={$file_name}; charset=utf-8"); header("Content-Length: {$file_size}"); readfile($full_file_name); exit; } /** * 检测文件类型 * @param string $file_name 文件名 * @return */ private function check_file_ext($file) { $file_ext = strtolower(substr($file, -4)); if (!in_array($file_ext, $this->allow)) exit('this file is deny!'); return true; } /** * 检测文件是否存在 * @param string $full_file_name 带目录的文件名 * @return */ private function check_file_exists($full_file_name) { if (!file_exists($full_file_name)) exit('this file does not exit!'); return true; } }