Exemple #1
0
 public function create($execution, $format, $hrefs)
 {
     $this->dirs = array();
     $this->files = array();
     $this->sc401 = false;
     $this->add_hrefs($hrefs);
     if ($this->sc401) {
         return 401;
     } else {
         if (count($this->dirs) === 0 && count($this->files) === 0) {
             return 404;
         }
     }
     $target = H5ai::normalize_path(sys_get_temp_dir(), true) . "h5ai-selection-" . microtime(true) . rand() . "." . $format;
     try {
         if ($execution === "shell") {
             if ($format === "tar") {
                 $cmd = Archive::$TAR_CMD;
             } else {
                 if ($format === "zip") {
                     $cmd = Archive::$ZIP_CMD;
                 } else {
                     return null;
                 }
             }
             $cmd = str_replace("[ROOTDIR]", "\"" . $this->h5ai->getRootAbsPath() . "\"", $cmd);
             $cmd = str_replace("[TARGET]", "\"" . $target . "\"", $cmd);
             $cmd = str_replace("[DIRS]", count($this->dirs) ? "\"" . implode("\"  \"", array_values($this->dirs)) . "\"" : "", $cmd);
             $cmd = str_replace("[FILES]", count($this->files) ? "\"" . implode("\"  \"", array_values($this->files)) . "\"" : "", $cmd);
             `{$cmd}`;
         } else {
             if ($execution === "php") {
                 $archive = new PharData($target);
                 foreach ($this->dirs as $archivedDir) {
                     $archive->addEmptyDir($archivedDir);
                 }
                 foreach ($this->files as $realFile => $archivedFile) {
                     $archive->add_file($realFile, $archivedFile);
                     // very, very slow :/
                 }
             }
         }
     } catch (Exeption $err) {
         return 500;
     }
     return @filesize($target) ? $target : null;
 }