企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ /** * 文件下载 * @param $filepath 文件路径 * @param $filename 文件名称 */ function file_down($filepath, $filename = '') { if(!$filename) $filename = basename($filepath); if(is_ie()) $filename = rawurlencode($filename); $filetype = fileext($filename); $filesize = sprintf("%u", filesize($filepath)); if(ob_get_length() !== false) @ob_end_clean(); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: none'); header('Content-type: '.$filetype); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-length: '.$filesize); readfile($filepath); exit; } ~~~ ~~~ /** * IE浏览器判断 */ function is_ie() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if((strpos($useragent, 'opera') !== false) || (strpos($useragent, 'konqueror') !== false)) return false; if(strpos($useragent, 'msie ') !== false) return true; return false; } ~~~ ~~~ /** * 取得文件扩展 * * @param $filename 文件名 * @return 扩展名 */ function fileext($filename) { return strtolower(trim(substr(strrchr($filename, '.'), 1, 10))); } ~~~