编程语言
首页 > 编程语言> > php – CodeIgniter zip存档,不包含文件夹

php – CodeIgniter zip存档,不包含文件夹

作者:互联网

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

我的目录:

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

标签:codeigniter-3,php,codeigniter,zip
来源: https://codeday.me/bug/20190824/1707654.html