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;
}
?>