1
我在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')
但是,這也打印出來,它重命名文件,但沒有。我在這裏做錯了什麼,或者是這個功能越野車?
謝謝!你是對的。 PHP.net文檔沒有很好地解釋。 – Jarred 2011-01-20 05:30:28