Example #1
0
 /**
  * unzip file
  *
  * @param	string	$a_file		full path/filename
  * @param	boolean	$overwrite	pass true to overwrite existing files
  */
 function unzip($a_file, $overwrite = false)
 {
     //global $ilias;
     $pathinfo = pathinfo($a_file);
     $dir = $pathinfo["dirname"];
     $file = $pathinfo["basename"];
     // unzip
     $cdir = getcwd();
     chdir($dir);
     $unzip = $this->ini->readVariable("tools", "unzip");
     $unzipcmd = $unzip . " -Z -1 " . ilUtil::escapeShellArg($file);
     exec($unzipcmd, $arr);
     $zdirs = array();
     foreach ($arr as $line) {
         if (is_int(strpos($line, "/"))) {
             $zdir = substr($line, 0, strrpos($line, "/"));
             $nr = substr_count($zdir, "/");
             //echo $zdir." ".$nr."<br>";
             while ($zdir != "") {
                 $nr = substr_count($zdir, "/");
                 $zdirs[$zdir] = $nr;
                 // collect directories
                 //echo $dir." ".$nr."<br>";
                 $zdir = substr($zdir, 0, strrpos($zdir, "/"));
             }
         }
     }
     asort($zdirs);
     foreach ($zdirs as $zdir => $nr) {
         ilUtil::createDirectory($zdir);
     }
     // real unzip
     if ($overvwrite) {
         $unzipcmd = $unzip . " " . ilUtil::escapeShellArg($file);
     } else {
         $unzipcmd = $unzip . " -o " . ilUtil::escapeShellArg($file);
     }
     exec($unzipcmd);
     chdir($cdir);
 }
 /**
  * Create thumbnail directory
  */
 function _createThumbnailDirectory($a_obj_id)
 {
     ilUtil::createDirectory(ilUtil::getWebspaceDir() . "/thumbs");
     ilUtil::createDirectory(ilUtil::getWebspaceDir() . "/thumbs/mm_" . $a_obj_id);
 }
 function importSave()
 {
     global $_FILES, $rbacsystem;
     global $ilias, $lng;
     // check if file was uploaded
     $source = $_FILES["scormfile"]["tmp_name"];
     if ($source == 'none' || !$source) {
         $ilias->raiseError("No file selected!", $ilias->error_obj->MESSAGE);
     }
     // check create permission
     if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs")) {
         $ilias->raiseError($lng->txt("no_create_permission"), $ilias->error_obj->WARNING);
     }
     // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
     switch ($__FILES["scormfile"]["error"]) {
         case UPLOAD_ERR_INI_SIZE:
             $ilias->raiseError($lng->txt("err_max_file_size_exceeds"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_FORM_SIZE:
             $ilias->raiseError($lng->txt("err_max_file_size_exceeds"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_PARTIAL:
             $ilias->raiseError($lng->txt("err_partial_file_upload"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_NO_FILE:
             $ilias->raiseError($lng->txt("err_no_file_uploaded"), $ilias->error_obj->MESSAGE);
             break;
     }
     $file = pathinfo($_FILES["scormfile"]["name"]);
     $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
     $file_path = $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId() . "/" . $_FILES["scormfile"]["name"];
     ilUtil::createDirectory($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
     ilUtil::unzip($file_path);
     ilUtil::renameExecutables($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     include_once "./Modules/Scorm2004/classes/ilSCORM13Package.php";
     $newPack = new ilSCORM13Package();
     $newPack->il_importSco($this->slm_object->getId(), $this->node_object->getId(), $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     $this->ctrl->redirect($this, "showOrganization");
 }
 function updateSocialBookmarkObject()
 {
     global $ilAccess, $rbacreview, $lng, $ilCtrl;
     if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
         $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
     }
     include_once './Services/Administration/classes/class.ilSocialBookmarks.php';
     $form = ilSocialBookmarks::_initForm($this, 'update');
     if ($form->checkInput()) {
         $title = $form->getInput('title');
         $link = $form->getInput('link');
         $file = $form->getInput('image_file');
         $active = $form->getInput('activate');
         $id = $form->getInput('sbm_id');
         if (!$file['name']) {
             ilSocialBookmarks::_updateSocialBookmark($id, $title, $link, $active);
         } else {
             $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
             $icon_path = ilUtil::getWebspaceDir() . DIRECTORY_SEPARATOR . 'social_bm_icons' . DIRECTORY_SEPARATOR . time() . '.' . $extension;
             $path = ilUtil::getWebspaceDir() . DIRECTORY_SEPARATOR . 'social_bm_icons';
             if (!is_dir($path)) {
                 ilUtil::createDirectory($path);
             }
             ilSocialBookmarks::_deleteImage($id);
             ilSocialBookmarks::_updateSocialBookmark($id, $title, $link, $active, $icon_path);
             ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $icon_path);
         }
         $this->editSocialBookmarksObject();
     } else {
         $this->__initSubTabs("editSocialBookmarks");
         $form->setValuesByPost();
         $this->tpl->setVariable('ADM_CONTENT', $form->getHTML());
     }
 }
Example #5
0
 /**
  * create work directory for image map editing
  */
 function createWorkDirectory()
 {
     if (!@is_dir(ilUtil::getDataDir() . "/map_workfiles")) {
         ilUtil::createDirectory(ilUtil::getDataDir() . "/map_workfiles");
     }
     $work_dir = $this->getWorkDirectory();
     if (!@is_dir($work_dir)) {
         ilUtil::createDirectory($work_dir);
     }
 }
 /**
  * Create a temporary file in an ILIAS writable directory
  *
  * @return	string File name of the temporary file
  * @static
  * 
  */
 public static function ilTempnam()
 {
     $temp_path = ilUtil::getDataDir() . "/temp";
     if (!is_dir($temp_path)) {
         ilUtil::createDirectory($temp_path);
     }
     $temp_name = tempnam($temp_path, "tmp");
     // --->
     // added the following line because tempnam creates a backslash on some
     // Windows systems which leads to problems, because the "...\tmp..." can be
     // interpreted as "...{TAB-CHARACTER}...". The normal slash works fine
     // even under windows (Helmut Schottmüller, 2005-08-31)
     $temp_name = str_replace("\\", "/", $temp_name);
     // --->
     unlink($temp_name);
     return $temp_name;
 }
 /**
  * import categories (static, also called by RootFolderGUI)
  */
 function _importCategories($a_ref_id, $withrol_tmp)
 {
     global $lng;
     require_once "./Modules/Category/classes/class.ilCategoryImportParser.php";
     $import_dir = ilObjCategoryGUI::_getImportDir();
     // create user import directory if necessary
     if (!@is_dir($import_dir)) {
         ilUtil::createDirectory($import_dir);
     }
     // move uploaded file to user import directory
     $file_name = $_FILES["importFile"]["name"];
     // added to prevent empty file names
     if (!strcmp($file_name, "")) {
         ilUtil::sendFailure($lng->txt("no_import_file_found"), true);
         $this->ctrl->redirect($this);
     }
     $parts = pathinfo($file_name);
     $full_path = $import_dir . "/" . $file_name;
     //move_uploaded_file($_FILES["importFile"]["tmp_name"], $full_path);
     ilUtil::moveUploadedFile($_FILES["importFile"]["tmp_name"], $file_name, $full_path);
     // unzip file
     ilUtil::unzip($full_path);
     $subdir = basename($parts["basename"], "." . $parts["extension"]);
     $xml_file = $import_dir . "/" . $subdir . "/" . $subdir . ".xml";
     // CategoryImportParser
     //var_dump($_POST);
     $importParser = new ilCategoryImportParser($xml_file, $a_ref_id, $withrol_tmp);
     $importParser->startParsing();
     ilUtil::sendSuccess($lng->txt("categories_imported"), true);
     $this->ctrl->redirect($this);
 }
 /**
  * Import upload into temp directory
  * 
  * @param string $a_hash unique form hash
  * @param string $a_field form field
  * @param string $a_tmp_name temp file name
  * @param string $a_name original file name
  * @param string $a_type file mime type
  * @param mixed $a_index form field index (if array)
  * @param mixed $a_sub_index form field subindex (if array)
  * @return bool 
  */
 protected function keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index = null, $a_sub_index = null)
 {
     global $ilUser;
     $user_id = $ilUser->getId();
     if (!$user_id || $user_id == ANONYMOUS_USER_ID) {
         return;
     }
     $a_name = ilUtil::getAsciiFileName($a_name);
     $tmp_file_name = implode("~~", array($user_id, $a_hash, $a_field, $a_index, $a_sub_index, str_replace("/", "~~", $a_type), str_replace("~~", "_", $a_name)));
     // make sure temp directory exists
     $temp_path = ilUtil::getDataDir() . "/temp";
     if (!is_dir($temp_path)) {
         ilUtil::createDirectory($temp_path);
     }
     move_uploaded_file($a_tmp_name, $temp_path . "/" . $tmp_file_name);
 }
Example #9
0
 /**
  * Move an uploaded media file to an public accessible temp dir to present it
  * 
  * @param string $file File path
  * @param string $name Name of the file
  * @access public
  */
 function moveUploadedMediaFile($file, $name)
 {
     $mediatempdir = CLIENT_WEB_DIR . "/assessment/temp";
     if (!@is_dir($mediatempdir)) {
         ilUtil::createDirectory($mediatempdir);
     }
     $temp_name = tempnam($mediatempdir, $name . "_____");
     $temp_name = str_replace("\\", "/", $temp_name);
     @unlink($temp_name);
     if (!ilUtil::moveUploadedFile($file, $name, $temp_name)) {
         return FALSE;
     } else {
         return $temp_name;
     }
 }