random1 Posted September 6, 2008 Share Posted September 6, 2008 How do you zip up a folder and all of it's subdirectories (all files) in .zip of .gz format using PHP? I want to be able to create a full backup of a website and offer it as saving to a server, a different server or as a download. Help is much appreciated Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 6, 2008 Share Posted September 6, 2008 information here. the comments are insightful: http://us.php.net/manual/en/ref.zip.php Quote Link to comment Share on other sites More sharing options...
random1 Posted September 7, 2008 Author Share Posted September 7, 2008 I ended up with the example code, it uses the zip PHP extension: <?php // Adding files to a .zip file, no zip file exists it creates a new ZIP file // increase script timeout value ini_set('max_execution_time', 5000); // create object $zip = new ZipArchive(); // open archive if ($zip->open('my-archive.zip', ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } // initialize an iterator // pass it the directory to be processed $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("themes/")); // iterate over the directory // add each file found to the archive foreach ($iterator as $key=>$value) { $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } // close and save archive $zip->close(); echo "Archive created successfully."; ?> I'll tweak this a bit and it should be okay. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.