复制代码 代码如下:
if (file_exists($file_path)) { //如果文件存在
$handle = fopen($file_path, "r");
while (!feof($handle)) {
$content = fgets($handle, 4096); //读取一行
echo $content; //输出到缓冲区,即php://stdout。达到缓冲区设置值后由tcp传给浏览器进行输出 一般到512字节就会通过网络输出给浏览器
}
fclose($handle);
}
复制代码 代码如下:
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
Header("Content-type: application/octet-stream"); //响应内容类型
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($filename). ' bytes');
Header('Content-Disposition: attachment; filename='.$filename); //HTTP响应头
新闻热点
疑难解答