在 PHP 中从 ZIP 中提取特定文件

发布于 2024-08-30 12:22:09 字数 216 浏览 2 评论 0原文

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

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

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

If I have a ZIP file whose structure is:

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

Using pclzip.lib.php how can I open up this ZIP file and extract directory1 (recursive) into a directory and then extract directory2 (recursive) into another directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一腔孤↑勇 2024-09-06 12:22:09

您应该能够使用 PCLZIP_OPT_BY_NAME 选项来选择要提取的存档内的哪个路径。 PCLZIP_OPT_PATH 应该确定该分支的写入位置。

但这只是浏览手册后的猜测——我从未使用过这个特殊的图书馆。

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.

初见你 2024-09-06 12:22:09
<?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';
}
?>
<?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';
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文