Updating your WEBAPP using PHP Functions – uploadapp program

Introduction:

This app download, extract the gunzip, backup the given config folder (single folder only) and replace the existing app file with updated files.

The app is tested on updating wordpress files. You can use if for update of owncloud, piwik, or modify it to upload files to your host server from your client computer. It make use of cURL and phar class of PHP. It works for gunzip update files only. For zip files, you would need to modify code of extr.php.

Main Code:

Important code for this app is:

  1. downloading file to host server
  2. extracting the gunzip
  3. and moving the backup and update files

PHP code for uploading a gunzip file to your host server with progress bar javascript:

PHP code for extracting gunzip file:

PHP code for moving and backup of folder:

 

Installation:

  1.  Download the app from http://enggprog.com/Download/Projects/upload/uploadapp.zip and extract on your computer.
  2.  Edit config.php and change following variables:
    • $remoteFile = url of download package.
    • $webpath = full absolute webpath of the app including the folder.
    • $dstwebpath = full absolute webpath of the owncloud/req app including the folder. Files will be extracted here.
    • $srcfoldername = extracted files will be in this folder. It shall be the name of root folder of update package.
    • $dstfoldername = extracted files will be moved to this folder. This folder must exist on your server.
    • $cfgfolder = single folder (usually config folder) that is inside $dstfoldername folder to backup during update.
    • $cfgfolderbak = name of backup folder
    • $ctimeout = timeout of download time, increase for large files.
  3. Copy the url of index.php file of this app and paste it in your browser.

Download:

Download source code of uploadapp v0.1

Note:

  1.  Incorrect folder/file name can produce error.
  2.  Backup your full app directory before first time use.

References:

  1. stackoverflow.com
  2. php.net