php - How to change this script to zip an array of dirs? -
i'm new , new php. found script online zip directory , i've edited sends zip browser download , deletes file server.
it works fine, zip multiple directories instead of one.
how need alter script accomplish this?
$date = date('y-m-d'); $dirtobackup = "content"; $dest = "backups/"; // make sure directory exists! $filename = "backup-$date.zip"; $archive = $dest.$filename; function foldertozip($folder, &$zipfile, $subfolder = null) { if ($zipfile == null) { // no resource given, exit return false; } // check if $folder has slash @ end, if not, append 1 $folder .= end(str_split($folder)) == "/" ? "" : "/"; $subfolder .= end(str_split($subfolder)) == "/" ? "" : "/"; // start going through files in $folder $handle = opendir($folder); while ($f = readdir($handle)) { if ($f != "." && $f != "..") { if (is_file($folder . $f)) { // if find file, store // if have subfolder, store there if ($subfolder != null) $zipfile->addfile($folder . $f, $subfolder . $f); else $zipfile->addfile($folder . $f); } elseif (is_dir($folder . $f)) { // if find folder, create folder in zip $zipfile->addemptydir($f); // , call function again foldertozip($folder . $f, $zipfile, $f); } } } } // create zip $z = new ziparchive(); $z->open($archive, ziparchive::create); foldertozip($dirtobackup, $z); $z->close(); // download zip file $file_name = basename($archive); header("content-type: application/zip"); header("content-disposition: attachment; filename=$file_name"); header("content-length: " . filesize($archive)); readfile($archive); // delete file server unlink($archive); exit;
thanks help!
irma
set $dirtobackup to
$dirtobackup = array("restricted","ci");
and :
foreach($dirtobackup $d){ foldertozip($d, $z, $d); }
thats all. regards,
Comments
Post a Comment