Skip to content

Commit

Permalink
Bugfix: recursive directory download works.
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimeprojects committed Oct 30, 2012
1 parent 56987b6 commit 4cd1e43
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/_include/fun_archive.php
Expand Up @@ -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) {
Expand Down

0 comments on commit 4cd1e43

Please sign in to comment.