PDA

View Full Version : [PHP] Backup Your Site


x3sphere
08-12-2007, 07:37 AM
This will create a tar.gz archive on the fly of the directory you're running the PHP script from.

<?php
// get current working directory
$dir = getcwd();

// start headers
header('Content-Type: application/x-gzip');
$content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment';
header('Content-Disposition: ' . $content_disp . '; filename="backup.tar.gz"');
header('Pragma: no-cache');
header('Expires: 0');

// create the backup
passthru( "tar cz $dir");
?>

Useful for when you want to create a quick backup of a certain directory on your site. Of course leaving the file on your server is dangerous, either password protect it or delete the file once you've finished.

Darkchild
08-13-2007, 03:15 AM
nice! i understand some of it, (I'm not that experient in PHP)

Cheezeball99
08-13-2007, 03:53 AM
I need to learn more PHP. I know very little/none. Make some PHP tuts, d00d! I mean, it ain't THAT bigga' deal, I'm sure I can find some, but it'd be cool.:smile: