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