<?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()实现文件下载
最新推荐文章于 2022-12-11 18:07:30 发布