Ejemplo n.º 1
0
 /**
  * unzips in given directory and processes uploaded zip for use as single files
  *
  * @author Jan Hippchen
  * @version 1.6.9.07
  * @param string $a_directory Directory to unzip 
  * @param string $a_file Filename of archive
  * @param boolean structure  True if archive structure is to be overtaken
  * @param integer $ref_id ref_id of parent object, if null, files wont be included in system (just checked)
  * @param string containerType object type of created containerobjects (folder or category)
  * @throws ilFileUtilsException
  */
 function processZipFile($a_directory, $a_file, $structure, $ref_id = null, $containerType = null, $tree = null, $access_handler = null)
 {
     global $lng;
     include_once "Services/Utilities/classes/class.ilUtil.php";
     self::$new_files = array();
     $pathinfo = pathinfo($a_file);
     $file = $pathinfo["basename"];
     // Copy zip-file to new directory, unzip and remove it
     // TODO: check archive for broken file
     //copy ($a_file, $a_directory . "/" . $file);
     move_uploaded_file($a_file, $a_directory . "/" . $file);
     ilUtil::unzip($a_directory . "/" . $file);
     unlink($a_directory . "/" . $file);
     //echo "-".$a_directory . "/" . $file."-";
     // Stores filename and paths into $filearray to check for viruses
     // Checks if filenames can be read, else -> throw exception and leave
     ilFileUtils::recursive_dirscan($a_directory, $filearray);
     // if there are no files unziped (->broken file!)
     if (empty($filearray)) {
         throw new ilFileUtilsException($lng->txt("archive_broken"), ilFileUtilsException::$BROKEN_FILE);
         break;
     }
     // virus handling
     foreach ($filearray["file"] as $key => $value) {
         // remove "invisible" files
         if (substr($value, 0, 1) == "." || stristr($filearray["path"][$key], "/__MACOSX/")) {
             unlink($filearray["path"][$key] . $value);
             unset($filearray["path"][$key]);
             unset($filearray["file"][$key]);
             continue;
         }
         $vir = ilUtil::virusHandling($filearray["path"][$key], $value);
         if (!$vir[0]) {
             // Unlink file and throw exception
             unlink($filearray[path][$key]);
             throw new ilFileUtilsException($lng->txt("file_is_infected") . "<br />" . $vir[1], ilFileUtilsException::$INFECTED_FILE);
             break;
         } else {
             if ($vir[1] != "") {
                 throw new ilFileUtilsException($vir[1], ilFileUtilsException::$INFECTED_FILE);
                 break;
             }
         }
     }
     // If archive is to be used "flat"
     if (!$structure) {
         foreach (array_count_values($filearray["file"]) as $key => $value) {
             // Archive contains same filenames in different directories
             if ($value != "1") {
                 $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
             }
         }
         if (isset($doublettes)) {
             throw new ilFileUtilsException($lng->txt("exc_upload_error") . "<br />" . $lng->txt("zip_structure_error") . $doublettes, ilFileUtilsException::$DOUBLETTES_FOUND);
             break;
         }
     } else {
         $mac_dir = $a_directory . "/__MACOSX";
         if (file_exists($mac_dir)) {
             ilUtil::delDir($mac_dir);
         }
     }
     // Everything fine since we got here; so we can store files and folders into the system (if ref_id is given)
     if ($ref_id != null) {
         ilFileUtils::createObjects($a_directory, $structure, $ref_id, $containerType, $tree, $access_handler);
     }
 }