当前位置:首页 > PHP教程 >

php利用header()实现文件下载

发布时间:2016-07-27 15:34:03 作者:佚名 阅读:(330)

php利用header()实现文件下载

<?php
$file = './test.png';
$filename = basename($file);

//设置头信息
header("Content-Type:application/octet-stream");
header("Content-Disposition:attachment;filename='$filename'");
header("Content-Transfer-Encoding:binary");

//输出文件内容
$handle = fopen($file,'r');
$content = fread($handle, filesize($file));
echo $content;
fclose($handle);

欢迎分享转载→ php利用header()实现文件下载

© 2015-2021 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们