根据while循环解压缩文件

时间:2016-07-20 10:58:02

标签: php

我正在尝试使用PHP在线宣布机器更新。 我希望如果他们去domain.com/appupdates或者他们可以下载更新的任何内容,取决于他们是否有现有更新或非。 例如,机器加载链接并给它的机器更新值,所以如果它有2个更新,它将会:index.php?machineupdate = 2 然后代码就可以了,我将发布更新3,因为它有更新2,如果我总共有5个更新,机器只有2,它将继续循环,直到我有所有更新然后给出一些命令说所有更新成功。 以下是我的代码。

主要需要查看的部分是"//Update code below"

希望你们能帮助我。

PHP:

<?PHP
$zipped = new ZipArchive;
$filename = '1.zip';
$machineupdate = $_GET['machineupdate'];

$zipfile = "updates/$filename";

$result = $zipped->open($zipfile);


if(isset($_GET['key']))
{
    if(!empty($_GET['key']))
    {
        if(isset($_GET['machineupdate']))
{
         if(!empty($_GET['machineupdate']))
    {
        $key = $_GET['key'];
        if($key == "hello" or $key =="apple")
        {
        if ($result === TRUE) {
            $dirname = uniqid();

            $zipped->extractTo("temp/$dirname");

            $zipped->close();
            echo 'Successful!';
            $success = TRUE;

                            } else {

                        echo 'error';

                    $success == FALSE;
                                    }

        if ($success == TRUE) {
        echo nl2br ("\n Folder created and files extracted. Now for the update! \n");

     //Update code below


     //Add while loop below
    $a = 0;
    $count = 0;
    while ($a < $machineupdate) {
        $a = $a + 1;
        $count ++;
        echo "$a ";
    }
    echo "<p>Loop count = {$count}</p>";
    //end loop



     //Deletes file and folder once updated ->

        array_map('unlink', glob("temp/$dirname/*.*"));

        rmdir("temp/$dirname");

                            }
        }
        else
        {
            die("Invalid Key Specified. - You entered an unknown key, please match with one in our database.");
        }
    }
    else
    {
        die("No update specified. - Please enter your current update to continue");
    }
}
else
{
        die("No update specified. - Please enter your current update to continue");
    }
    }
else
    {
        die("No update specified. - Please enter your current update to continue");
    }
}
else
{
    die("No key specified. - Please enter your key to continue");
}

?>

1 个答案:

答案 0 :(得分:3)

怎么样:

$updateVersion=5;

function UpdateManchine($currentVersion, $updateVersion){

   if($currentVersion >= $updateVersion){
     echo="You are up to date";
   }
   else{

    //... Do your update here
    Return TRUE
   }


}

让机器使用当前的更新版本调用该函数。