/** * Download the db folder as one zip file, for easy backup. */ function backup_db() { global $Paths, $zipfile; // make the zipfile.. include_once 'modules/zip.lib.php'; $zipfile = new zipfile(); adddirtozip("db/"); // get the zipp0red data.. $zipped = $zipfile->file(); // trigger a download. $basename = "pivot_db_" . date("Ymd") . ".zip"; header("Content-disposition: attachment; filename={$basename}"); header("Content-type: application/zip"); header("Pragma: no-cache"); header("Expires: 0"); echo $zipped; }
/** * Function used by the 'backup db' option: * adds a directory (recursively) to the zip. * * @param string $dirname * @return void */ function adddirtozip($dirname) { $d = dir($dirname); while (false !== ($entry = $d->read())) { if ($entry != "." && $entry != "..") { if (is_dir($dirname . $entry)) { adddirtozip($dirname . $entry . "/"); } else { addfiletozip($dirname . $entry); } } } $d->close(); }