Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfix: recursive directory download works.

  • Loading branch information...
commit 4cd1e4317b9ab63ee340e94e8aa9705ff03b5c1d 1 parent 56987b6
Claudio Klingler authored
Showing with 33 additions and 8 deletions.
  1. +33 −8 src/_include/fun_archive.php
41 src/_include/fun_archive.php
View
@@ -81,18 +81,43 @@ function zip_items($dir, $name)
function zip_download($directory, $items)
{
- $zipfile = new ZipStream("downloadsxz.zip");
+ $zipfile = new ZipStream("downloads.zip");
foreach ($items as $item)
{
- $filename = $directory.DIRECTORY_SEPARATOR.$item;
- if (!@file_exists($filename))
+ _zipstream_add_file($zipfile, $directory, $item);
+ }
+ $zipfile->finish();
+}
+
+function _zipstream_add_file($zipfile, $directory, $file_to_add)
+{
+ $filename = $directory.DIRECTORY_SEPARATOR.$file_to_add;
+
+ if (!@file_exists($filename))
+ {
+ show_error($filename." does not exist");
+ }
+
+ if (is_file($filename))
+ {
+ _debug("adding file $filename");
+ return $zipfile->add_file($file_to_add, file_get_contents($filename));
+ }
+
+ if (is_dir($filename))
+ {
+ _debug("adding directory $filename");
+ $files = glob($filename.DIRECTORY_SEPARATOR."*");
+ foreach ($files as $file)
{
- show_error($filename." does not exist");
+ $file = str_replace($directory.DIRECTORY_SEPARATOR, "", $file);
+ _zipstream_add_file($zipfile, $directory, $file);
}
- _debug("adding item $filename");
- $zipfile->add_file($filename, file_get_contents($filename));
- }
- $zipfile->finish();
+ return True;
+ }
+
+ _error("don't know how to handle $file_to_add");
+ return False;
}
function tar_items($dir,$name) {
Please sign in to comment.
Something went wrong with that request. Please try again.