栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

PHP:再次强制下载文件和IE,

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP:再次强制下载文件和IE,

这将检查IE的版本并相应地设置标头。

// assume you have a full path to file stored in $filenameif (!is_file($filename)) {  die('The file appears to be invalid.');}$filepath = str_replace('\', '/', realpath($filename));$filesize = filesize($filepath);$filename = substr(strrchr('/'.$filepath, '/'), 1);$extension = strtolower(substr(strrchr($filepath, '.'), 1));// use this unless you want to find the mime type based on extension$mime = array('application/octet-stream');header('Content-Type: '.$mime);header('Content-Disposition: attachment; filename="'.$filename.'"');header('Content-Transfer-Encoding: binary');header('Content-Length: '.sprintf('%d', $filesize));header('Expires: 0');// check for IE only headersif (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)) {  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  header('Pragma: public');} else {  header('Pragma: no-cache');}$handle = fopen($filepath, 'rb');fpassthru($handle);fclose($handle);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435391.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号