【问题标题】:CodeIgniter zip archive with exclude a folder排除文件夹的 CodeIgniter zip 存档
【发布时间】:2016-01-26 14:41:43
【问题描述】:

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

我的目录:

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

【问题讨论】:

    标签: php codeigniter zip codeigniter-3


    【解决方案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 上测试

    【讨论】:

      【解决方案2】:

      您可以进行这样的锻炼,无需手动进入您创建的新目录

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

      【讨论】:

      • 然后它看起来是自动化的。如果创建了新文件夹,则无需重新编码 :)
      猜你喜欢
      • 1970-01-01
      • 2016-11-13
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多