使用php的压缩文件赢得';我不能在windows下工作

使用php的压缩文件赢得';我不能在windows下工作,php,compression,Php,Compression,我试图压缩一些视频文件的飞行使用php和强迫压缩文件下载。下面是我写的代码 $files_todownload_string = ' movie1.mov movie2.mov ' header('Content-Type: application/x-gzip'); header('Content-Type: application/octet-stream'); header('Content-disposition: attachment; filename="file.zip"');

我试图压缩一些视频文件的飞行使用php和强迫压缩文件下载。下面是我写的代码

$files_todownload_string = ' movie1.mov movie2.mov '

header('Content-Type: application/x-gzip');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="file.zip"');
header( 'Content-Transfer-Encoding: binary' ); 

$fp = popen('zip -v - ' . $files_todownload_string, 'r');
$bufsize = 8192;
$buff = '';
while( !feof($fp) ) {
$buff = fread($fp, $bufsize);
echo $buff;
print "
";
}
pclose($fp);
压缩完成得很好,zip文件下载成功。但是,当我试图在windows操作系统中打开zip文件时,它不会打开。它表示压缩文件已损坏

有人帮忙吗?提前感谢。

删除
打印”
";


您正在添加额外的字节。

我找到了此解决方案。压缩文件在所有操作系统Linux、Windows和Mac中都能正常工作

代码如下:

$files_array = array();
$files_array[] = 'file1.mov';
$files_array[] = 'file2.mov';
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
foreach($files_array as $k => $v) {
$zip->addFile( $path.$files_available[$v] );
}
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');
header( 'Content-Transfer-Encoding: binary' ); 
ob_end_clean();
readfile($file);

感谢大家抽出时间。

尝试删除打印“”;但结果是一样的。还有其他建议吗?您正在将文件类型设置为gzip。也许试试zip类型。最后,服务器发送到浏览器时zip文件是否已压缩?如果使用php zip函数并等待文件压缩,会怎么样?将文件类型设置为gzip不是问题,因为我可以在linux中成功下载并解压缩文件,但在windows中失败。另外,在压缩过程中没有时间延迟问题。