简体   繁体   English

在codeigniter中创建zip文件

[英]create zip file in codeigniter

I want to create zip file using codeigniter 我想使用codeigniter创建zip文件
here is my code 这是我的代码

$this->zip->read_dir($path, FALSE);
$this->zip->archive($path . '.zip'); 

Code is creating zip file properly. 代码正确创建了zip文件。 But when I extract zip, files are inside the folder. 但是,当我提取zip时,文件位于文件夹中。

Here is my folder structure 这是我的文件夹结构

config
   /abc.xml
   /index.html
   /images
        /logo.png
   /data

When I try to compress config folder, while extracting new config folder created. 当我尝试压缩配置文件夹时,同时解压缩创建的新配置文件夹。 Is there any way to compress only files and folder which are inside config folder? 有什么方法可以只压缩config文件夹中的文件和文件夹?

You could, by reading the directory yourself and after that invoking $this->zip->read_file() on each separate file. 您可以自己读取目录,然后在每个单独的文件上调用$this->zip->read_file() Something along these lines (not tested): 遵循以下原则(未经测试):

$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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM