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.

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

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器