2013-11-04 57 views
1

我有這樣一段代碼命名..,一切工作正常,但重命名Zip文件中添加和使用PHP

 $zip = new ZipArchive(); 
     $zipPath = 'images/userfiles/'.$company_details->company_name.'_products.zip'; 

      $emptydir = $company_details->company_name.'_product_logos'; 

      if ($zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) { 
       $new_filename = substr($my_file, strrpos($my_file, '/') + 1); 
       $zip->addFile($my_file, $new_filename); 

        $zip->addEmptyDir($emptydir); 

        foreach($parts_list as $pl) { 
        if(!empty($pl['part_image'])){  
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . $baseurl . '/images/group-logo/' . $pl['part_image'])) { 

           $img_file = 'images/group-logo/' . $pl['part_image']; 
           $new_filename2 = substr($img_file, strrpos($img_file, '/') + 1);       
           $zip->addFile($img_file,$emptydir . '/' . $new_filename2);         

      /*********the problem here****** 
       Is there any way to rename the file that i added on the previous line to something else ,already tried zip rename and renameindex but not working 

    for example i want to rename the file $new_filename2 to $new_filename2.'something' with out affecting the original file's name 

P.S the files to be renamed are inside another folder in the zip 


      *******************************/ 



          } 
         } 
        } 


       $zip->close(); 
      } 
+0

你嘗試$ zip->重命名($舊的,新的$)或$ zip-> renameName($舊的,新的$) http://us3.php.net/manual/en/ziparchive.renamename .php – JLoppert

+0

@JL oppert ..例如顯示打開一個zip並重命名它..在我的情況下,我想重新命名的fly..beffore添加到zip – coolguy

回答

0

好吧,我想通了

郵編創建的file..you着鎖重命名上的蒼蠅,關閉後再重新命名

$zip->addFile('.....'); 
.... 
$zip->close(); 

和開放的拉鍊和重命名

0

既然你不想影響原始文件的問題,我會認爲你將需要包含一份副本聲明。就像是;

$file = '$new_filename2'; 
$newfile = '$new_filename2.zip'; 

if (!copy($file, $newfile)) { 
echo "failed to copy $file...\n";