2013-11-04 54 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";