我尝试创建完整的网站备份,但我想从存档中排除文件夹。
我的目录:
/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');
答案 0 :(得分:5)
你可以锻炼这样的东西,你永远不必手动输入你创建的新目录
$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');
答案 1 :(得分:1)
我的解决方案是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上进行了测试