I am creating a php file that will update my site after pulling it off of BitBucket (Git repo). It downloads a zip file of the entire master or a commit, then unzips it in the website's folder.
The problem I am having is there is a randomly named folder that contains all the files in the zip file.
My zip file's contents is similar:
master.php
- (bitbucketusername)-(reponame)-(commitnumber)
- folder1
- index.php
- test.php
- index.php
- config.php
- etc...
but how can I "bypass" the "randomly" named folder and extract the contents of the folder to the website's root?
echo "Unzipping update...<br>" . PHP_EOL;
$zip = new ZipArchive;
$res = $zip->open($filename);
if ($res === TRUE) {
$zip->extractTo('/path/to/www');
$zip->close();
} else {
echo 'Error: The zip file could not be opened...<br>' . PHP_EOL;
}
Found a related question here:
Operating with zip file in PHP
But how can I make it get the "randomly" named folder's name?
Unzip the files to a tmp directory and then mv the files out from the "randomly" named parent folder to the folder that you want to.