PHP IE中下载附件问题解决方法
程序员文章站
2023-12-09 13:17:33
重点: 1、在ie中下载附件之前要清空缓存。 2、中文文件名要用urlencode编码。 复制代码 代码如下: header("pragma: "); //不加的话,ie中...
重点:
1、在ie中下载附件之前要清空缓存。
2、中文文件名要用urlencode编码。
header("pragma: "); //不加的话,ie中会提示目标主机无法访问
header("cache-control: "); //不加的话,ie中会提示目标主机无法访问
header("content-type: $type");
header("accept-ranges: bytes");
header("content-transfer-encoding:base64");
header("accept-length: " . filesize($path_c));
header("content-disposition: attachment; filename=" .urlencode($filename)); //ie中不用urlencode中文名会出现乱码
readfile($path_c);
exit;
或
header('content-description: file transfer');
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename='.urlencode(basename($file) )); //ie中不用urlencode中文名会出现乱码
header('content-transfer-encoding: binary'); //二进制传输
header('expires: 0');
header('cache-control: must-revalidate, post-check=0, pre-check=0'); //不加的话,ie中会提示目标主机无法访问
header('pragma: public'); //不加的话,ie中会提示目标主机无法访问
header('content-length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
1、在ie中下载附件之前要清空缓存。
2、中文文件名要用urlencode编码。
复制代码 代码如下:
header("pragma: "); //不加的话,ie中会提示目标主机无法访问
header("cache-control: "); //不加的话,ie中会提示目标主机无法访问
header("content-type: $type");
header("accept-ranges: bytes");
header("content-transfer-encoding:base64");
header("accept-length: " . filesize($path_c));
header("content-disposition: attachment; filename=" .urlencode($filename)); //ie中不用urlencode中文名会出现乱码
readfile($path_c);
exit;
或
复制代码 代码如下:
header('content-description: file transfer');
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename='.urlencode(basename($file) )); //ie中不用urlencode中文名会出现乱码
header('content-transfer-encoding: binary'); //二进制传输
header('expires: 0');
header('cache-control: must-revalidate, post-check=0, pre-check=0'); //不加的话,ie中会提示目标主机无法访问
header('pragma: public'); //不加的话,ie中会提示目标主机无法访问
header('content-length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;