本节内容:
php文件下载实例,支持中文文件名。
例子:
复制代码 代码示例:
/**
* php文件下载示例
* by www.jbxue.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 '\r\n您下载的文件由脚本学堂编辑部提供!感谢您的下载。';
exit;
?>
您可能感兴趣的文章:
php文件下载的函数(支持多种格式)
php文件下载类(支持多种文件类型)
php实现文件下载的代码
php 强制文件下载的一段代码
php header函数 文件下载时直接提示保存的代码
php header函数实现文本文件下载的方法
php使用header发送各种类型文件下载的例子
php强制性文件下载的函数