【发布时间】:2015-09-03 12:39:37
【问题描述】:
我的文件夹中有一些文件。我使用以下 php 代码将文件传输到浏览器(带有标题)。
我以 .7z 格式下载了正确长度的文件,但我无法解压缩。 如果我用 ftp 传输相同的文件,我可以毫无问题地解压缩它。 从我的服务器我可以毫无问题地解压缩它。所以错误在php中的某个地方
private function pushToBrowser($file){
if(!$file){ // file does not exist
die('file not found');
} else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Content-length: ".filesize($file).";\n");
// read the file from disk
readfile($file);
}
}
代码的用法
$this->pushToBrowser($path);
【问题讨论】:
-
我猜你发送了错误的内容类型?尝试将 content-type 设置为 application/x-7z-compressed。
标签: php linux file header transfer