1

Using PHP, I am developing a CMS. This needs to support website backups.

Musts:

  • Compressed ZIP Folders
  • Must work on at least Linux and Windows
  • Must work on PHP 5.0, PHP 4 would be nice
  • I just need a function/class, don't link me open-source software as I need to do this my self
  • CMS does not need MySQL backups as it is XML powered

I've already checked into ZipArchive in PHP. Here is all I got so far. However when I try to go to the ZIP file on the server that it says it created, I get a 404? It isn't working and I don't know why.

<?php
    $filename = CONTENT_DIR . 'backups/' . date( 'm-d-Y_H-i-s' ) . '.zip';

    if ( $handle = opendir( ABS_PATH ) ) {
        $zip = new ZipArchive();

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

        $string = '';
        while ( ( $file = readdir( $handle ) ) !== false ) {
            $zip->addFile( $file );
            $string .= "$file\n<br>";
        }
        closedir( $handle );
        $string .= "Status of the Zip Archive: " . $zip->status;
        $string .= "<br>System status of the Zip Archive: " . $zip->statusSys;
        $string .= "<br>Number of files in archive: " . $zip->numFiles;
        $string .= "<br>File name in the file system: " . $zip->filename;
        $string .= "<br>Comment for the archive: " . $zip->comment;
        $zip->close();
        echo $string;
    }
?>
2
  • Just a thought, your backup dir isn't inside the folder you're trying to back up, is it?
    – moopet
    Sep 29, 2012 at 16:20
  • No. The backup script is in "/home/content/61/9295861/html/cms-admin/includes/tools-backups.php" and the backup directory is at "/home/content/61/9295861/html/cms-content/backups/".
    – Solo
    Sep 29, 2012 at 16:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.