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 Link to comment https://forums.phpfreaks.com/topic/123004-compressing-folder-and-subfolders/ 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 Link to comment https://forums.phpfreaks.com/topic/123004-compressing-folder-and-subfolders/#findComment-635161 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. Link to comment https://forums.phpfreaks.com/topic/123004-compressing-folder-and-subfolders/#findComment-635591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.