PHP Classes

File: sample.php

Recommend this page to a friend!
  Classes of Mark Simkin   Backup Class   sample.php   Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: This is an example using a simple html form.
Class: Backup Class
Backup directory files to local file or ftp server
Author: By
Last change:
Date: 18 years ago
Size: 3,333 bytes
 

Contents

Class file image Download
<html>
<head>
<title>Backup.class</title>
</head>
<body>
<?php
require 'class.backup.php';

/*
This is an example using the backup.class
*/

$output = '
    <div>
    <form name="myForm" method="post" action="'
. $_SERVER['PHP_SELF'] . '">
    <div style="float:left; margin-right:10px;">
        <div style="border:solid 1px #444; width:150px; background-color:silver; margin-top:11px; padding-bottom:10px;">
            <div style="margin:8px;"><strong>Mode</strong></div>
            <input type="radio" name="mode" value="FTP" /> FTP
            <br />
            <input type="radio" name="mode" value="FILESYSTEM" /> FILESYSTEM
        </div>
        <div><input type="submit" value="backup" style="margin-top:10px;" /></div>
    </div>
    <div style="float:left;margin-right:10px;">
        <div style="margin-top:10px;"><label for="host" style="margin-bottom:10px;"><strong>Host:</strong></label><br /><input type="text" name="host" id="host" style="width:425px;" /></div>
        <div style="margin-top:10px;"><label for="user" style="margin-bottom:10px;"><strong>User:</strong></label><br /><input type="text" name="user" id="user" style="width:425px;" /></div>
        <div style="margin-top:10px;"><label for="password" style="margin-bottom:10px;"><strong>Password:</strong></label><br /><input type="password" name="password" id="target" style="width:425px;" /></div>
        <div style="margin-top:10px;"><label for="target" style="margin-bottom:10px;"><strong>Target:</strong></label><br /><input type="text" name="target" id="target" style="width:425px;" /></div>
        <div style="margin-top:10px;"><label for="source" style="margin-bottom:10px;"><strong>Source:</strong></label><br /><textarea name="source" cols="50" rows="10" id="source"></textarea></div>
    </div>
    <div style="float:left; margin-right:10px;">
        <div style="margin-top:10px;"><label for="maxage" style="margin-bottom:10px;"><strong>Max. Age:</strong></label><br /><input type="text" name="maxage" id="maxage"></div>
        <div style="margin-top:10px;"><label for="minage" style="margin-bottom:10px;"><strong>Min. Number:</strong></label><br /><input type="text" name="minage" id="minage"></div>
    </div>
    </form>
    <div style="float:none; clear:both;"></div>
    </div>
'
;
echo
$output;


if(isset(
$_POST['mode']) && isset($_POST['source']))
{
   
$zeilen = explode("\n",stripslashes($_POST['source']));
    for(
$c = 0;$c < count($zeilen);$c++)
    {
        if(
$c+1 != count($zeilen))
        {
           
$zeilen[$c] = substr($zeilen[$c],0,strlen($zeilen[$c])-1);
        }
    }
   
$obj = new backupclass($zeilen);
    if(!empty(
$_POST['maxage'])) {
       
$obj->set_max_age($_POST['maxage']);
    }
    if(!empty(
$_POST['minage'])) {
       
$obj->set_min_backup_number($_POST['minage']);
    }
   
    if(
$_POST['mode'] == 'FILESYSTEM') {
        if(!empty(
$_POST['target'])) {
           
$obj->check_archives('filesys',$_POST['target']);
           
$obj->backup('filesys',$_POST['target']);
        }
        else {
           
$obj->check_archives('filesys');
           
$obj->backup('filesys');
        }
    }
    else if(
$_POST['mode'] == 'FTP') {
       
$obj->config_ftp($_POST['host'],$_POST['user'],$_POST['password']);

        if(!empty(
$_POST['target'])) {
           
$obj->check_archives('ftp',$_POST['target']);
           
$obj->backup('ftp',$_POST['target']);
        }
        else {
           
$obj->check_archives('ftp');
           
$obj->backup('ftp');
        }
    }
print_r($obj->log);
}
?>
</body>
</html>