问题
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