Operating with zip file in PHP [closed]

早过忘川 提交于 2019-12-13 09:07:37

问题


Inside webserver, I'm downloading zip and unziping with function below.

$zip = new ZipArchive;
$res = $zip->open('tip.zip');
if ($res === TRUE) {
    $zip->extractTo("$dest/");
    $zip->close();
} else {
    die('ZIP not supported on this server!');
}

The problem is, when I unzip with this script, I am getting the folder inside zip (there is folder inside zip). But, I need to get files, folders inside zip's child folder, not folder itself.

In other words

So I need:

  • to execute some function like moveRecursively("$username-$reponame-$node", $destination); where $destination is root and then delete this folder
  • or do this action somehow while unziping and unzip driectly child folders contents into folder where script located (public_html in my case)

Can't figure out solution. Please help.


回答1:


This should be actual obvious.

Pass the name of that folder to your script (next to the name of the zip file), then move all files from inside that folder (after you extracted them) to the wanted destination:

$zip = new ZipArchive;
$res = $zip->open('tip.zip');
if ($res !== TRUE) {
    die('ZIP not supported on this server!');
}

$zip->extractTo("$dest/");
$zip->close();
rename("$dest/dirname/", "$dest/");


来源:https://stackoverflow.com/questions/12767797/operating-with-zip-file-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!