【问题标题】:Extracting specific files from ZIP in PHP在 PHP 中从 ZIP 中提取特定文件
【发布时间】:2010-04-25 02:16:56
【问题描述】:

如果我有一个 ZIP 文件,其结构是:

  -directory1 DIR
      -files in here
  -directory2 DIR
      -more files in here

如何使用 pclzip.lib.php 打开这个 ZIP 文件并将 directory1(递归)提取到一个目录中,然后将 directory2(递归)提取到另一个目录中。

【问题讨论】:

    标签: php zip extract


    【解决方案1】:

    您应该能够使用 PCLZIP_OPT_BY_NAME 选项来选择要在存档中提取的路径。 PCLZIP_OPT_PATH 应该确定该分支将被写入何处。

    但这只是浏览the manual 后的猜测——我从未使用过这个特定的库。

    【讨论】:

      【解决方案2】:
      <?php
      $zip = new ZipArchive;
      $res = $zip->open('test_im.zip');
      if ($res === TRUE) {
          $zip->extractTo('directory1', array('item.gif', 'file1.php'));
          $zip->extractTo('directory2', array('item1.gif', 'file2.php'));
          $zip->close();
          echo 'ok';
      } else {
          echo 'failed';
      }
      ?>
      

      【讨论】:

      • 这是一个zip扩展的例子,它不是pclzip。
      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多