Extracting specific files from ZIP in PHP

后端 未结 2 531
無奈伤痛
無奈伤痛 2021-01-17 03:22

If I have a ZIP file whose structure is:

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

Using pclzip.li

相关标签:
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';
    }
    ?>
    
    0 讨论(0)
  • 2021-01-17 03:53

    You should be able to use the PCLZIP_OPT_BY_NAME option to select which path inside the archive you want to extract. PCLZIP_OPT_PATH ought to determine where that branch will be written.

    But that's just a guess after browsing the manual -- I've never used this particular library.

    0 讨论(0)
提交回复
热议问题