irishwill200 irishwill200 - 3 months ago 14
PHP Question

unzipping files depending on while loop

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 ("\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");
}

?>

Answer

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.

Comments