$zip 重命名函数在 PHP 中不起作用
我正在 PHP 中提取一个 zip 文件并尝试将其重命名为 content.txt。这是我的代码:
if($this->copyFile($this->src,$this->dest)) {
$this->log .= "Successfully copied the file. Starting unzip.<br />";
$res = $this->zip->open($this->dest);
if ($res === TRUE) {
$this->zip->extractTo("/htdocs/content-refresh/");
$this->extracted = $this->zip->getNameIndex(0);
$this->log .= "Extracted ".$this->extracted." onto our server.<br />";
if($this->zip->renameIndex(0,'content.txt')) {
$this->log .= "Renamed update file to content.txt.<br />";
} else {
$this->log .= "Could not rename update file to content.txt.<br />";
}
$this->zip->close();
$this->log .= "The update file is ready to go. Now you can use the update functions.<br />";
} else {
$this->log .= "Could not unzip the file.<br />";
}
}
这是文件输出:
Successfully copied the file. Starting unzip.
Extracted Hotel_All_Active 01-19-11.txt onto our server.
Renamed update file to content.txt.
The update file is ready to go. Now you can use the update functions.
问题是它没有重命名文件。我也尝试过:
$this->zip->renameName(strval($this->extracted),'content.txt')
但这也打印出它重命名了文件,但没有。我在这里做错了什么,还是这个函数有问题?
I am extracting a zip file in PHP and trying to rename it to content.txt. Here is my code:
if($this->copyFile($this->src,$this->dest)) {
$this->log .= "Successfully copied the file. Starting unzip.<br />";
$res = $this->zip->open($this->dest);
if ($res === TRUE) {
$this->zip->extractTo("/htdocs/content-refresh/");
$this->extracted = $this->zip->getNameIndex(0);
$this->log .= "Extracted ".$this->extracted." onto our server.<br />";
if($this->zip->renameIndex(0,'content.txt')) {
$this->log .= "Renamed update file to content.txt.<br />";
} else {
$this->log .= "Could not rename update file to content.txt.<br />";
}
$this->zip->close();
$this->log .= "The update file is ready to go. Now you can use the update functions.<br />";
} else {
$this->log .= "Could not unzip the file.<br />";
}
}
Here is the file output:
Successfully copied the file. Starting unzip.
Extracted Hotel_All_Active 01-19-11.txt onto our server.
Renamed update file to content.txt.
The update file is ready to go. Now you can use the update functions.
The problem is that it does not rename the file. I have also tried:
$this->zip->renameName(strval($this->extracted),'content.txt')
But that also prints out that it renamed the file, but does not. Am I doing something wrong here, or is this function buggy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
renameIndex()
函数是用于重命名存档内的文件。查看 PHP 手册中该函数的代码,您可以看到它正在修改存档:
您需要使用
rename()
函数代替。The
renameIndex()
function is for renaming a file inside an archive.Looking at the code in the PHP Manual for that function, it's you can see it's modifying the archive:
You need to use the
rename()
function instead.