static function download($data, $save_name, $is_path = false) { $extension = preg_replace('/.*\\./', '', $save_name); $mime_type = config($extension, 'mime_type'); empty($mime_type) and $mime_type = 'application/octet-stream'; $file_name = help::process_download_file_name($save_name); if ($is_path) { if (is_file($data) && ($fp = fopen($data, 'rb')) !== false) { self::send_download_file_header($mime_type, filesize($data), $file_name); if (ob_get_level() !== 0 && ob_end_clean() === false) { ob_clean(); } while (!feof($fp) && ($source = fread($fp, 1048576)) !== false) { echo $source; } fclose($fp); exit; } throw new Exception('read download file fail', 108); } self::send_download_file_header($mime_type, strlen($data), $file_name); exit($data); }