我正在尝试使用以下代码从目录创建一个 zip 文件,并通过 http 下载将其提供给用户:
// write the file
file_put_contents($path . "/index.html", $output);
// zip up the contents
chdir($path);
exec("zip -r {$course->name} ./");
$filename = "{$course->name}.zip";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' .urlencode($filename));
header('Content-Transfer-Encoding: binary');
readfile($filename);
我能够创建 zip 文件,但通过 http 下载它不起作用。如果我下载使用 ftp 客户端创建的 zip 文件,那么 Mac 的 Stuffit Expander 会很好地解压缩文件,但如果我通过 http 下载它,mac 解压缩器会创建一个无限循环。我的意思是说我下载的文件称为 course.zip,然后解压缩该文件会得到 course.zip.cpgz,然后解压缩该文件会再次得到 course.zip ......等等。
有人有想法么?
谢谢!