drzyeetvt41077335 2019-02-14 07:33
浏览 213
已采纳

要在$ zip-> extractTo中合并而不是替换

I have used the following code to unzip a zip folder after upload.

  /* here it is really happening */

    if(move_uploaded_file($source, $targetzip)) {
        $zip = new ZipArchive();
        $x = $zip->open($targetzip);  // open the zip file to extract
        if ($x === true) {
            echo $targetdir; exit;
            $zip->extractTo($targetdir); // place in the directory with same name  
            $zip->close();
            unlink($targetzip);
        }
        $message = "Your .zip file was uploaded and unpacked.";
    } else {    
        $message = "There was a problem with the upload. Please try again.";
    } 

It is working fine. But the only problem is the that the folder is replaced by the new one uploaded. I want to merge it.

Suppose i have a zip folder. One.zip a b c

When i upload this, it should merge with the (One) folder which is already in the upload server. So the previous folders in the (One) folder should not be replaced.

I think It is understandable now. Please help to do the trick.

  • 写回答

1条回答 默认 最新

  • dongtuoji5396 2019-02-14 08:04
    关注

    You can con-cat current time & date with you target fine name:

    $targetdir = $targetdir."_".str_replace(' ',"/",date('Y-m-d H:i:s'));
    

    Using this logic, you fine will not replace with previous file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)