-
-
/**
- * php文件下载示例
- * by bbs.it-home.org
- */
- ob_start();
- $ua = $_SERVER["HTTP_USER_AGENT"];
- $filename ="脚本学堂_文件下载.doc";//注意转码
- $encoded_filename = urlencode($filename);
- //兼容各种浏览器
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
- header('Content-Type: application/octet-stream');
- if (preg_match("/MSIE/", $ua))
- {
- header('Content-Disposition: attachment; filename="'.urldecode($encoded_filename).'"');
- }
- else if (preg_match("/Firefox/", $ua))
- {
- header('Content-Disposition: attachment; filename*="gbk\'\''.$filename.'"');
- }
- else
- {
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- }
- ob_clean();
- flush();
- readfile($filename);
- echo '\r\n您下载的文件由程序员之家编辑部提供!感谢您的下载。';
- exit;
- ?>
复制代码
|