dsklzerpx64815631 2016-07-20 10:58 采纳率: 100%
浏览 22
已采纳

根据while循环解压缩文件

I am trying to announce machine updates online using PHP. I am hoping to make it so if they go to domain.com/appupdates or whatever they can download updates depending on if they have an existing update or non. Example, the machine loads the link and gives its machines update value so if it has 2 updates it will go: index.php?machineupdate=2 Then the code will go ok, I will ship out update 3 since it has update 2 and if I have 5 updates in total and the machine only has 2 it will keep looping till I have all updates then give some command saying all updates successful. Below is my code.

The section mainly needed to look at is the "//Update code below"

Hope you guys can assist me.

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 ("
 Folder created and files extracted. Now for the update! 
");

     //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条回答 默认 最新

  • dream3323 2016-07-22 13:38
    关注

    how about this:

    $updateVersion=5;
    
    function UpdateManchine($currentVersion, $updateVersion){
    
       if($currentVersion >= $updateVersion){
         echo="You are up to date";
       }
       else{
    
        //... Do your update here
        Return TRUE
       }
    
    
    }
    

    have the machine call the function with its current update version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)