Coder Social home page Coder Social logo

php-auto-update's Introduction

Installation

  • Copy the update folder to your project (what should be updated)
  • Create a update.ini on your server (where the updates are from)

Important: Please notice that PHP needs write permissions to update the files on your webserver

Description

The update folder consists of two files:

  • index.php - includes the class and calls the update
  • update.php - update class

You should not call the update out of your project (what happens if you try to update a file which is in use at the moment?). At your server you need a folder with a configuration file update.ini and the ziped versions.

update.ini

The update.ini should look like this:

[1]
version = 0.1
url = http://example.com/updates/0.1.zip

[2]
version = 0.2
url = http://example.com/updates/0.2.zip

You can name the versions whatever you want but the sections (for example [1]) has to be an integer so that the class can compare the versions. You cannot compare 1.4.3-13.r1441 with 1.4.3-12.r1445 without problems. The url has to be absolute.

Update files

Zip your project and rename it to version.zip. The zip file should include all of the project files.

Check for an update

/*
 * Index.php in the folder update
 */

require('update.php');

$update = new AutoUpdate(true); //Enable logging

$update->currentVersion = 1;

/*
 * In this example the folder 'updateUrl' includes 3 files, 0.1.zip, 0.2.zip and update.ini
 */
$update->updateUrl = 'http://example.com/updates';

$latest = $update->checkUpdate();

if ($latest !== false) {
	if ($latest > $update->currentVersion) {
		//Install new update
		echo "New Version: ".$update->latestVersionName."<br>";
		
		//You can also stop here and let the user decide when to update.
		echo "Installing Update...<br>";
		if ($update->update()) {
			echo "Update successful!";
		}
		else {
			echo "Update failed!";
		}
		
	}
	else {
		echo "Current Version is up to date";
	}
}
else {
	echo $update->getLastError();
}

php-auto-update's People

Contributors

robinflyhigh avatar thelfensdrfer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.