php 文件下载的相关代码 兼容所有浏览器

来源:互联网 发布:网配圈用什么软件 编辑:程序博客网 时间:2024/06/09 01:57

php 文件下载的相关代码 兼容所有浏览器

$params=$this->_getAllParams();$filename=$params['fname'];//文件的原始名字$encoded_filename=str_replace('+', '%20', urlencode($filename));$url=$params['furl'];$ua = $_SERVER["HTTP_USER_AGENT"];if (file_exists($url)) {ob_end_clean();//这里要clean一下不然文件内容会多处四个空行header('Content-Type: application/octet-stream');if (preg_match("/MSIE/", $ua)) {//IE情况header('Content-Disposition: attachment; filename="' . $encoded_filename. '"');} else if (preg_match("/Firefox/", $ua)) {//火狐header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');} else {header('Content-Disposition: attachment; filename="' . $filename . '"');}header('Content-Length: ' . filesize($url));ob_end_clean();//这里要clean一下不然文件内容会多处四个空行readfile($url);flush();}

相关内容可以查看:http://www.jb51.net/article/26196.htm

其实也可以在.htaccess 加入AddType application/octet-stream .txt 之类的

原创粉丝点击