(php)如何从zip存档功能中排除文件或文件夹?

时间:2018-07-22 14:59:59

标签: php lamp

我正在使用以下代码从LAMP Web服务器上的文件夹创建一个zip存档:

$the_folder = '/var/www/html';
$zip_file_name = 'snapshot-'.date('Ymd-Hi').'.zip';

class FlxZipArchive extends ZipArchive {

  public function addDir($location, $name) {
    $this->addEmptyDir($name);
    $this->addDirDo($location, $name);
  }

  private function addDirDo($location, $name) {

    $name .= '/';         
    $location .= '/';
    $dir = opendir($location);

    while ($file = readdir($dir))    {
      if ($file == '.' || $file == '..') continue;
      $do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
      $this->$do($location . $file, $name . $file);
    }
  } 
}

$za = new FlxZipArchive;
$res = $za->open($zip_file_name, ZipArchive::CREATE);

if( $res === TRUE ) {
  $za->addDir($the_folder, basename($the_folder));
  $za->close();
}

两个问题可以改善上述情况:

  1. 如何修改以排除扩展名为.zip的文件?
  2. 如何修改以排除名为snapshots的文件夹?

0 个答案:

没有答案