PHP下载文件需要定义的代码头

//返回的文件
header("Content-type:application/octet-stream");
//按照字节大小返回
header("Accept-Ranges:bytes");
//显示文件大小 file_size一定要提前算好
header("Content-length:file_size");
//客户端弹出下载的对话框,显示对应的文件名
header("Content-Disposition:attachment; filename=".$filename);
//打开文件
$fp = fopen($filename, 'r');
//传输文件
while (!feof($fp)){
    $data = fread($fp, 1024);
    echo $data;
}
//关闭文件
fclose($fp);

猜你喜欢

转载自blog.csdn.net/ZhaoXinDa/article/details/82694832