Php 解压跳过文件夹的文件

Php 解压跳过文件夹的文件,php,bitbucket,unzip,Php,Bitbucket,Unzip,我正在创建一个php文件,在将我的站点从BitBucket(Git repo)中删除后,它将更新我的站点。它下载整个主文件或提交文件的zip文件,然后将其解压缩到网站文件夹中 我遇到的问题是有一个随机命名的文件夹,其中包含zip文件中的所有文件 我的zip文件的内容类似: master.php - (bitbucketusername)-(reponame)-(commitnumber) - folder1 - index.php

我正在创建一个php文件,在将我的站点从BitBucket(Git repo)中删除后,它将更新我的站点。它下载整个主文件或提交文件的zip文件,然后将其解压缩到网站文件夹中

我遇到的问题是有一个随机命名的文件夹,其中包含zip文件中的所有文件

我的zip文件的内容类似:

master.php
    - (bitbucketusername)-(reponame)-(commitnumber)
        - folder1
            - index.php
            - test.php
        - index.php
        - config.php
        - etc...
但是我怎样才能“绕过”这个“随机”命名的文件夹,并将文件夹的内容提取到网站的根目录中呢

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;
}
echo“解压缩更新…
”。PHP_EOL; $zip=新的ZipArchive; $res=$zip->open($filename); 如果($res==TRUE){ $zip->extractTo('/path/to/www'); $zip->close(); }否则{ echo“错误:无法打开zip文件…
”。PHP\u EOL; }
在此处找到一个相关问题:


但是我如何才能让它获得“随机”命名文件夹的名称呢?

将文件解压缩到tmp目录,然后将文件从“随机”命名的父文件夹中移动到您想要的文件夹中

echo "Unzipping update...<br>" . PHP_EOL;
$zip = new ZipArchive;
$res = $zip->open($filename);
if ($res === TRUE) {
    $zip->extractTo('/tmp/unzip');
    $directories = scandir('/tmp/unzip');
    foreach($directories as $directory){
        if($directory!='.' and $directory!='..' ){
            if(is_dir($directory)){
                  // rcopy from http://ben.lobaugh.net/blog/864/php-5-recursively-move-or-copy-files
                  rcopy('/tmp/unzip/'.$directory,'/path/to/www');
                  // rm /tmp/unzip here
            }
    }
} 

    $zip->close();
} else {
    echo 'Error: The zip file could not be opened...<br>' . PHP_EOL;
}
echo“解压缩更新…
”。PHP_EOL; $zip=新的ZipArchive; $res=$zip->open($filename); 如果($res==TRUE){ $zip->extractTo('/tmp/unzip'); $directories=scandir('/tmp/unzip'); foreach($directory作为$directory){ 如果($directory!='.'和$directory!='.'){ if(is_dir($directory)){ //抄袭http://ben.lobaugh.net/blog/864/php-5-recursively-move-or-copy-files rcopy('/tmp/unzip/'.$directory'/path/to/www'); //rm/tmp/在此处解压缩 } } } $zip->close(); }否则{ echo“错误:无法打开zip文件…
”。PHP\u EOL; }
他的rmove有很多错误,所以我把它改成了rcopy,并用我自己的代码删除了它。好答案。经过这些编辑后,效果很好。谢谢!:)rcopy实际上花费了大约三分之一的时间来完成!