用php header() 实现文件下载,出现问题

2025-04-19 18:20:42
推荐回答(1个)
回答1:

$file=fopen('文件地址',"r");
$size=filesize('文件地址');
header("Content-Type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".$size);
header("Content-Disposition: attachment; filename=文件名称");
echo fread($file, $size);
fclose($file);