当下载需要用户登录验证权限、并且可以自定义下载的文件名等情况下需要以附件形式下载文件,代码如下:
(由于 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 条评论。