mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-28 22:16:00 -04:00
Changes a lot... forgot to commit.
This commit is contained in:
parent
6a5c35ad9a
commit
ebec62adac
212 changed files with 2578 additions and 2166 deletions
63
src/_h5ai/php/inc/ZipIt.php
Normal file
63
src/_h5ai/php/inc/ZipIt.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class ZipIt {
|
||||
private $h5ai;
|
||||
|
||||
public function __construct($h5ai) {
|
||||
|
||||
$this->h5ai = $h5ai;
|
||||
}
|
||||
|
||||
public function zip($hrefs) {
|
||||
|
||||
$zipFile = tempnam("/tmp", "h5ai-download");
|
||||
$zip = new ZipArchive();
|
||||
|
||||
if (!$zip->open($zipFile, ZIPARCHIVE::CREATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($hrefs as $href) {
|
||||
$d = dirname($href);
|
||||
$n = basename($href);
|
||||
if ($this->h5ai->getHttpCode($this->h5ai->getAbsHref($d)) === "h5ai" && !$this->h5ai->ignoreThisFile($n)) {
|
||||
$localFile = $this->h5ai->getAbsPath($href);
|
||||
$file = preg_replace("!^" . $this->h5ai->getDocRoot() . "!", "", $localFile);
|
||||
if (is_dir($localFile)) {
|
||||
$this->zipDir($zip, $localFile, $file);
|
||||
} else {
|
||||
$this->zipFile($zip, $localFile, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
return $zipFile;
|
||||
}
|
||||
|
||||
private function zipFile($zip, $localFile, $file) {
|
||||
|
||||
if (is_readable($localFile)) {
|
||||
$zip->addFile($localFile, $file);
|
||||
}
|
||||
}
|
||||
|
||||
private function zipDir($zip, $localDir, $dir) {
|
||||
|
||||
if ($this->h5ai->getHttpCode($this->h5ai->getAbsHref($localDir)) === "h5ai") {
|
||||
$zip->addEmptyDir($dir);
|
||||
$files = $this->h5ai->readDir($localDir);
|
||||
foreach ($files as $file) {
|
||||
$localFile = $localDir . "/" . $file;
|
||||
$file = $dir . "/" . $file;
|
||||
if (is_dir($localFile)) {
|
||||
$this->zipDir($zip, $localFile, $file);
|
||||
} else {
|
||||
$this->zipFile($zip, $localFile, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue