2011-01-20 12 views
1

PHPでzipファイルを抽出して、content.txtという名前に変更しようとしています。

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. 

問題は、それがファイルの名前を変更しないということである。ここでは

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 />"; 
     } 
    } 

ファイル出力されます。ここに私のコードです。私も試みました:

$this->zip->renameName(strval($this->extracted),'content.txt') 

しかし、これはファイルの名前が変更されたことを表示しますが、表示されません。私はここで何か間違っているのですか、この関数のバグですか?

答えて

3

renameIndex()ファンクションは、内のファイル名をに変更するためのものです。

$zip = new ZipArchive; 
$res = $zip->open('test.zip'); 
if ($res === TRUE) { 
    $zip->renameIndex(2,'newname.txt'); 
    $zip->close(); 
} else { 
    echo 'failed, code:' . $res; 
} 

があなたの代わりにrename()機能を使用する必要があります。

その関数のPHPマニュアルのコードを見てみると、それはあなたがそれがアーカイブを修正だ見ることができます。

+0

ありがとうございました!あなたは正しいです。 PHP.netのドキュメントでは、そのことについては説明していません。 – Jarred

関連する問題