2016-07-20 2 views
1

PHPを使用してマシンのアップデートをオンラインでアナウンスしようとしています。 domain.com/appupdatesにアクセスした場合や、既存のアップデートがあるかどうかに応じてアップデートをダウンロードできるものであれば、そのようにしたいと考えています。 例では、マシンがリンクをロードし、マシンにアップデート値を与えるので、2つのアップデートがある場合は、index.php?machineupdate = 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"); 
} 

?> 
+2

、問題は何ですか?何が起きているのか、起こっていないのかは不明です – RamRaider

答えて

3

方法:

$updateVersion=5; 

function UpdateManchine($currentVersion, $updateVersion){ 

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

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


} 

は、マシンが現在の更新版で関数を呼び出しています。

関連する問題