ZipArchive::getFromName 找不到文件名
知道我在这里做错了什么吗?它总是随着“再见”而死去。 zip 存档内有一个 index.php 文件。
$zip = new ZipArchive;
$zip->open($source);
$test = $zip->getFromName('index.php');
if(!$test) {
die('bye bye');
} else {
die($test);
}
Any idea what I am doing wrong here? It keeps dying with 'bye bye'. There is an index.php file inside the zip archive.
$zip = new ZipArchive;
$zip->open($source);
$test = $zip->getFromName('index.php');
if(!$test) {
die('bye bye');
} else {
die($test);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,您应该做的第一件事是确保您已正确打开它,因为这也可能会失败:
除此之外,请确保您绝对确定您的文件规范正确。如果有必要,您可以使用
getNameIndex
一次枚举一个条目,并在此过程中打印出它们的名称,类似于:浪费我的时间告诉你检查
$source
的值。您可能需要检查一下,以防万一。Well, the first thing you should do is ensure that you've opened it okay since that can fail as well:
Other than that, make sure you are absolutely certain that your file specification is correct. If necessary, you can use
getNameIndex
to enumerate the entries one at a time, printing out their names in the process, something like:And I'm assuming that I would be wasting my time telling you to check the value of
$source
. You may want to check, just in case.在 PHP 8 中,如果您正忙于构建存档并尝试对存档中的有效文件使用 getFromName(),也可能会发生这种情况。不管我怎么努力,我都是假的。
例如。
步骤 3 每次都返回 false。
但是,
步骤 3 现在会按预期返回文件内容。
因此,插入步骤 A 和 B 使 getFromName() 按预期工作。
希望这可以帮助别人不要像我刚才那样浪费太多时间:(
As at PHP 8 this can also occur if you are busy building an archive and you try and use getFromName() on a valid file in the archive. I got false no matter what I tried.
eg.
Step 3 returns false every time.
However
Step 3 now returns the contents of the file as expected.
So inserting steps A and B made getFromName() work as expected.
Hope this helps someone not waste as much time as I just did :(