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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失