├── README.md ├── config.php ├── current_version.txt ├── index.php ├── loader.gif ├── update-functions.php ├── update.js ├── version └── vnum_1.txt └── version_check.php /README.md: -------------------------------------------------------------------------------- 1 | # Simple-PHP-Auto-Update-System 2 | Allow users to update your web software with one click using PHP/Jquery and Text Files. 3 | 4 | 5 | Note: The (current_version.txt) on the external server only needs to contain the version number. -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /current_version.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | Update Program. Click here. 6 | 7 |
8 |
-------------------------------------------------------------------------------- /loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seangarciafm/Simple-PHP-Auto-Update-System/755a33e282f5a2324f6dd29bb5b8b7b60a52311c/loader.gif -------------------------------------------------------------------------------- /update-functions.php: -------------------------------------------------------------------------------- 1 | 0); 10 | }else{ 11 | // success message, continue to unzip 12 | $copy = 1; 13 | } 14 | // check for verification 15 | if($copy == 1){ 16 | 17 | $path = pathinfo(realpath($local_file), PATHINFO_DIRNAME); 18 | // unzip update 19 | $zip = new ZipArchive; 20 | $res = $zip->open($local_file); 21 | if($res === TRUE){ 22 | $zip->extractTo( $path ); 23 | $zip->close(); 24 | // success updating files 25 | $data = array("unzip" => 1); 26 | // delete zip file 27 | unlink($local_file); 28 | // update users local version number file 29 | $userfile = fopen ("version/vnum_". $_POST['uid'] .".txt", "w"); 30 | $user_vnum = fgets($userfile); 31 | fwrite($userfile, $_POST['vnum']); 32 | fclose($userfile); 33 | }else{ 34 | // error updating files 35 | $data = array("unzip" => 0); 36 | // delete potentially corrupt file 37 | unlink($local_file); 38 | } 39 | } 40 | // send the json data 41 | echo json_encode($data); 42 | ?> -------------------------------------------------------------------------------- /update.js: -------------------------------------------------------------------------------- 1 | // function to reorder 2 | $(document).ready(function(){ 3 | // check users files and update with most recent version 4 | $(".version_check").on('click',function(e) { 5 | //$(".loading").show(); 6 | var uid = $(this).attr("id"); 7 | var info = "uid="+uid+"&vcheck=1"; 8 | $.ajax({ 9 | beforeSend: function(){ 10 | $(".loading").html('
'); 11 | }, 12 | type: "POST", 13 | url: "version_check.php", 14 | data: info, 15 | dataType: "json", 16 | success: function(data){ 17 | // clear loading information 18 | $(".loading").html(""); 19 | // check for version verification 20 | if(data.version != 0){ 21 | var uInfo = "uid="+uid+"&vnum="+data.version 22 | $.ajax({ 23 | beforeSend: function(){ 24 | $(".loading").html('
'); 25 | }, 26 | type: "POST", 27 | url: "update-functions.php", 28 | data: uInfo, 29 | dataType: "json", 30 | success: function(data){ 31 | // check for version verification 32 | if(data.copy != 0){ 33 | if(data.unzip == 1){ 34 | // clear loading information 35 | $(".version_check").html(""); 36 | // successful update 37 | $(".loading").html("Successful Update!"); 38 | }else{ 39 | // error during update/unzip 40 | $(".loading").html("
Sorry, there was an error with the update."); 41 | } 42 | } 43 | }, 44 | error: function() { 45 | // error 46 | $(".loading").html('
There was an error updating your files.'); 47 | } 48 | }); 49 | }else{ 50 | // user has the latest version already installed 51 | $(".version_check").html(""); 52 | $(".loading").html("You already have the latest version."); 53 | } 54 | }, 55 | error: function() { 56 | // error 57 | $(".loading").html('
There was an error checking your latest version.'); 58 | } 59 | }); 60 | }); 61 | }); -------------------------------------------------------------------------------- /version/vnum_1.txt: -------------------------------------------------------------------------------- 1 | 22 -------------------------------------------------------------------------------- /version_check.php: -------------------------------------------------------------------------------- 1 | 0); 15 | }else{ 16 | // data 17 | $data = array("version" => $vnum); 18 | } 19 | // send the json data 20 | echo json_encode($data); 21 | ?> --------------------------------------------------------------------------------