目录是这样的:
home/
file1.html
file2.html
Another_Dir/
file8.html
Sub_Dir/
file19.html
Run Code Online (Sandbox Code Playgroud)
我使用PHPMyAdmin中使用的相同PHP Zip类http://trac.seagullproject.org/browser/branches/0.6-bugfix/lib/other/Zip.php.我不确定如何压缩目录而不仅仅是文件.这是我到目前为止所拥有的:
$aFiles = $this->da->getDirTree($target);
/* $aFiles is something like, path => filetime
Array
(
[home] =>
[home/file1.html] => 1251280379
[home/file2.html] => 1251280377
etc...
)
*/
$zip = & new Zip();
foreach( $aFiles as $fileLocation => $time ){
$file = $target . "/" . $fileLocation;
if ( is_file($file) ){
$buffer = file_get_contents($file);
$zip->addFile($buffer, $fileLocation);
}
}
THEN_SOME_PHP_CLASS::toDownloadData($zip); // this bit works ok
Run Code Online (Sandbox Code Playgroud)
但是当我尝试解压缩相应的下载zip文件时,我得到"不允许操作"
这个错误只发生在我尝试解压缩我的mac时,当我通过命令行解压缩文件解压缩时.我是否需要在下载时发送特定的内容类型,目前为'application/zip'