您当前位置: 首页 » 后端 » PHP 附件形式的下载

PHP 附件形式的下载

2010年02月03日 | 发表评论(0) 查看评论

当下载需要用户登录验证权限、并且可以自定义下载的文件名等情况下需要以附件形式下载文件,代码如下:
(由于 poor IE 的特殊性,需要为它做特别处理)

header("Content-type: application/octet-stream");
$isIE and $filename = mb_convert_encoding( $filename, 'GBK' , 'UTF-8' ); # IE 不认识UTF-8的中文文件名,所以转换为GBK编码
header('Content-Disposition: attachment; filename="'.$filename.'"'); # 备注: 文件名要做安全过滤,防止跨站攻击
echo file_get_contents($filepath);
分类:

后端

| 标签:

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据