是否可以使用 php 打开和编辑 zip 文件内的文件?

发布于 2024-11-29 00:29:08 字数 287 浏览 2 评论 0原文

我正在开发一个 WordPress 主题,需要一些配置才能正常工作。

当我说配置时,我的意思是 config.php 需要稍微编辑一下(设置一些变量值)。

现在我想知道是否可以进入 zip 文件,制作完整的临时副本(对于特定用户。也许使用会话 ID?)并编辑副本中的 config.php 文件以设置一些变量值。然后关闭临时 zip 文件并为用户回显该文件的链接,以供下载。

将设置的变量值将来自我网站上的表单,用户将在其中下载主题。

这只是我的一厢情愿,还是我还有机会?

谢谢!

I'm working on a WordPress theme which needs abit of configuration to be working properly.

When i say configuration, i mean config.php needs to be edited slightly (setting some variables value).

Now i was wondering if it is possible to be able to go into a zip file, make a complete temporary duplicate (for a specific user. Maybe using session ID's?) AND edit the config.php file in the duplicate to set some variables value. Then close the temporary zip file and echo a link out to the file for the user, ready for download.

The variables value that will be set will be from a form on my site where users will download the theme.

Is this just wishful thinking, or do I have a chance?

Thanks!

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

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

发布评论

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

评论(3

只为守护你 2024-12-06 00:29:08

您可以提取文件,更改它,然后将其重新添加回存档(假设您有 ZipArchive 类已安装)。

<?php
    $zip = new ZipArchive;
    $res = $zip->open('yourarchive.zip');
    if ($res === TRUE) {
        $zip->extractTo('/my/destination/dir/', 'config.php');

        // do your edits to the file

        $zip->addFile('config.php');
        $zip->close();
    }
?>

You can extract the file, change it, and then re-add it back to the archive (assuming that you have the ZipArchive class installed).

<?php
    $zip = new ZipArchive;
    $res = $zip->open('yourarchive.zip');
    if ($res === TRUE) {
        $zip->extractTo('/my/destination/dir/', 'config.php');

        // do your edits to the file

        $zip->addFile('config.php');
        $zip->close();
    }
?>
绅士风度i 2024-12-06 00:29:08

使用 ZipArchive 类完全可以做到这一点。您可以用它打开、创建、扩展和保存 Zip 档案。

This is entirely possible using the ZipArchive class. You open, create, expand and save Zip archives with it.

伏妖词 2024-12-06 00:29:08

当然有可能。

然而,您需要编写一些 php 代码来完成您想要的操作。

在 php.net 站点上,您可以在这里找到 zip 函数的文档 http://php。 net/manual/en/book.zip.php

我不会为您编写任何代码,但您需要取消的步骤如下:

1. copy zip file to temp area
2. open temp zip file
3. extract file from zip to temp area
4. delete file from temp zip
5. do changes to file in temp area
6. add temp file to zip
7. close zip file
8. stream zip file to client
9. delete temp files.

sure it's possible.

You will however need to write some php code which does what you want.

on the php.net site you can find documentation for the zip functions here http://php.net/manual/en/book.zip.php

Im not going to write any code for you, but the steps you need to undego is the following:

1. copy zip file to temp area
2. open temp zip file
3. extract file from zip to temp area
4. delete file from temp zip
5. do changes to file in temp area
6. add temp file to zip
7. close zip file
8. stream zip file to client
9. delete temp files.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文