gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:30:39 24 4
gpt4 key购买 nike

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

我的目录:

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

关于php - 带有排除文件夹的 CodeIgniter zip 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33363705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com