简体   繁体   中英

create zip file in codeigniter

I want to create zip file using codeigniter
here is my code

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

Code is creating zip file properly. But when I extract zip, files are inside the folder.

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?

You could, by reading the directory yourself and after that invoking $this->zip->read_file() on each separate 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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