zipsite.php 2.02 KB
<?php

// GRD ZIP ARCHIVER
// by Piotr GRD
// http://grd.go.pl/
// grd@gazeta.pl
// created 2008-05-05
// free to use and modify as long as you keep info above
// requirements: php zip extensions with ZipArchive class
// SETTINGS
// directory you want to compress with everything inside
// . - for root
// folder - for some folder
// folder/subfolder - for some subfolder
// do not add ending slash
$directory = dirname(__FILE__).DIRECTORY_SEPARATOR;
// the name of your zip archive to be created
$zipfile = '/var/www/reize.com.au/backup/site.zip';



// DO NOT TOUCH BELOW IF YOU DONT KNOW WHAT IT IS
// all the process below

$filenames = array();

// function that browse the directory and all subdirectories inside
$zip = new ZipArchive();

if ($zip->open($zipfile, ZIPARCHIVE::CREATE) !== TRUE) {
    exit("cannot open <$zipfile>\n");
}

function browse($dir, $zip) {
    // global $filenames;
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && is_file($dir . '/' . $file) && $file != $zipfile) {
                $extention = substr($file, -4);
                if ($extention != '.log' && $extention != ".zip") {
                    $filename = $dir . '/' . $file;
                    echo "Adding " . $dir . '/' . $file . "<br/>";
                    $zip->addFile($filename, $filename);
                }
            } else if ($file != "." && $file != ".." && is_dir($dir . '/' . $file)) {
                //if ($file == 'newsite' || $file == 'cache' || $file == 'images') {
                    
               // } else {
                    browse($dir . '/' . $file, $zip);
               // }
            }
        }
        closedir($handle);
    }
    return true;
}

browse($directory, $zip);

// creating zip archive, adding browsed files
//foreach ($filenames as $filename) {
//    echo "Adding " . $filename . "<br/>";
//    $zip->addFile($filename, $filename);
//}

echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>