带有排除文件夹的 CodeIgniter zip 存档

CodeIgniter zip archive with exclude a folder

我正在尝试创建完整站点备份,但我想从存档中排除一个文件夹。

我的目录:

/application/
/backups/      >>> I dont want to archive this folder because of nested archiving.
/themes/
/uploads/
.htaccess
index.php

尝试了以下代码:

$this->load->library('zip');
$this->zip->read_dir(FCPATH);
$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');

我的解决方案是 setting each root directories and files 如下所示的小手册:

$this->load->library('zip');

// Choose directory and files
$this->zip->read_dir(FCPATH.'application', false);
$this->zip->read_dir(FCPATH.'themes', false);
$this->zip->read_dir(FCPATH.'uploads', false);
$this->zip->read_file(FCPATH.'.htaccess', false);
$this->zip->read_file(FCPATH.'index.php', false);

$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');

在 CodeIgniter 3.x 和 Wamp 服务器上测试

您可以进行类似这样的锻炼,在这种情况下您将永远不必手动输入您创建的新目录

$this->load->library('zip');

$data = array_diff(scandir(FCPATH), array('..', '.','backups'));
// 'backups' folder will be excluded here with '.' and '..'

foreach($data as $d) {

    $path = FCPATH.$d;

    if(is_dir($path))
        $this->zip->read_dir($path, false);

    if(is_file($path))
        $this->zip->read_file($path, false);
}

$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');