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

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

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);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5122621.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存