Here is a modified version of the Paolo script to also include point files such as .htaccess, and it should also be a little faster since I replaced glob by opendir as shown here .
<?php $password = 'set_a_password'; // password to avoid listing your files to anybody if (strcmp(md5($_GET['password']), md5($password))) die(); // Make sure the script can handle large folders/files ini_set('max_execution_time', 600); ini_set('memory_limit','1024M'); //path to directory to scan if (!empty($_GET['path'])) { $fullpath = realpath($_GET['path']); // append path if set in GET } else { // else by default, current directory $fullpath = realpath(dirname(__FILE__)); // current directory where the script resides } $directory = basename($fullpath); // parent directry name (not fullpath) $zipfilepath = $fullpath.'/'.$directory.'_'.date('Ym-d_His').'.zip'; $zip = new Zipper(); if ($zip->open($zipfilepath, ZipArchive::CREATE)!==TRUE) { exit("cannot open/create zip <$zipfilepath>\n"); } $past = time(); $zip->addDir($fullpath); $zip->close(); print("<br /><hr />All done! Zipfile saved into ".$zipfilepath); print('<br />Done in '.(time() - $past).' seconds.'); class Zipper extends ZipArchive { // Thank to Paolo for this great snippet: http://stackoverflow.com/a/17440780/1121352 // Modified by LRQ3000 public function addDir($path, $parent_dir = '') { if($parent_dir != '' and $parent_dir != '.' and $parent_dir != './') { $this->addEmptyDir($parent_dir); $parent_dir .= '/'; print '<br />--> ' . $parent_dir . '<br />'; } $dir = opendir($path); if (empty($dir)) return; // skip if no files in folder while(($node = readdir($dir)) !== false) { if ( $node == '.' or $node == '..' ) continue; // avoid these special directories, but not .htaccess (except with GLOB which anyway do not show dot files) $nodepath = $parent_dir.basename($node); // with opendir if (is_dir($nodepath)) { $this->addDir($nodepath, $parent_dir.basename($node)); } elseif (is_file($nodepath)) { $this->addFile($nodepath, $parent_dir.basename($node)); print $parent_dir.basename($node).'<br />'; } } } } // class Zipper ?>
This is a stand-alone script, just copy it to a .php file (for example: zipall.php) and open it in your browser (for example: zipall.php?password=set_a_password , if you do not set the correct password, the page will remain blank for security) . You must use an FTP account to receive the zip file afterwards, this is also a security measure.
source share