1

我有这段代码..,一切正常,但重命名有问题

     $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();
            }
4

2 回答 2

0

由于您不想影响原始文件,我认为您将需要包含一份副本声明。就像是;

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

if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
于 2013-11-04T06:34:44.690 回答
0

好的,我想通了

Zip 在文件上创建一个锁..您不能即时重命名,关闭它并再次重命名

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

并再次打开 zip 并重命名

于 2013-11-06T08:55:10.193 回答