繁体   English   中英

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');

你可以锻炼这样的东西,你永远不必手动输入你创建的新目录

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

我的解决方案是一个小手册, 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 Server上测试

暂无
暂无

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

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