<?php
/**
*
php文件下载示例
* by www.jb200.com
*/
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 'rn您下载的文件由脚本学堂编辑部提供!感谢您的下载。';
exit;
?>