我想使用codeigniter来创建zip文件 这是我的代码
$this->zip->read_dir($path, FALSE);
$this->zip->archive($path . '.zip');
代码正在正确创建zip文件。但是当我提取zip时,文件就在文件夹中。
这是我的文件夹结构
config
/abc.xml
/index.html
/images
/logo.png
/data
当我尝试压缩配置文件夹时,同时解压缩创建的新配置文件夹。有没有办法只压缩配置文件夹里面的文件和文件夹?
答案 0 :(得分:0)
您可以自己阅读目录,然后在每个单独的文件上调用$this->zip->read_file()
。沿着这些方向的东西(未经测试):
$files = array();
if ($handle = opendir($path)) {
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
if (!is_dir($entry)) {
$files[] = $entry;
}
}
closedir($handle);
}
foreach($files as $file) {
$this->zip->read_file($file);
}