//这里是下载zip文件
header("Content-Type: application/zip");
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: " . filesize($file_path));
$ua = $_SERVER [ 'HTTP_USER_AGENT' ];
$file_name = basename($file_path);
$encoded_filename = urlencode($file_name);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
if (preg_match("/Chrome/", $ua))
{
header('Content-disposition: attachment; filename=' . $file_name);
}else if (preg_match("/Firefox/", $ua)) {
header("Content-Disposition: attachment; filename=\"" . $file_name."\"");//火狐要用双引号
}
else{
header('Content-Disposition: attachment; filename="' . rawurlencode($file_name) . '"');
}
header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
header('Content-Length: ' . filesize($file_path));
@readfile($file_path);
php 程序实现文件下载,兼容IE、Firefox、Chrome等浏览器
最新推荐文章于 2022-02-25 14:33:59 发布
本文详细介绍了使用PHP发送ZIP文件供下载的过程,包括设置HTTP头部信息以确保不同浏览器的兼容性,如Chrome、Firefox等,以及正确处理文件名编码。

747

被折叠的 条评论
为什么被折叠?



