49     protected \ILIAS\Filesystem\Util\Archive\LegacyArchives 
$unzip;
    67     protected \ILIAS\HTTP\Wrapper\WrapperFactory 
$wrapper;
    77         $this->
ctrl = $DIC->ctrl();
    78         $this->
lng = $DIC->language();
    79         $this->tpl = $DIC->ui()->mainTemplate();
    80         $this->wrapper = $DIC->http()->wrapper();
    82         $this->main_absolute_dir = realpath($main_absolute_directory);
    83         $this->ui_factory = $DIC->ui()->factory();
    84         $this->ui_renderer = $DIC->ui()->renderer();
    85         $this->unzip = $DIC->legacyArchives();
    89         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
    90         $this->
lng->loadLanguageModule(
"content");
   101         $this->allowed_suffixes = $a_suffixes;
   117         $this->forbidden_suffixes = $a_suffixes;
   130         if (empty($a_suffix)) {
   148         $this->allow_directories = $a_val;
   158         $this->post_dir_path = $a_val;
   168         $this->table_id = $a_val;
   178         $this->title = $a_val;
   188         $this->use_upload_directory = $a_val;
   203         if (!is_array($pars)) {
   227         $next_class = $this->
ctrl->getNextClass($this);
   228         $cmd = $this->
ctrl->getCmd(
"listFiles");
   229         if (substr($cmd, 0, 11) == 
"extCommand_") {
   230             $ret = $this->
extCommand(substr($cmd, 11, strlen($cmd) - 11));
   232             $ret = $this->$cmd();
   242         bool $a_single = 
true,
   243         bool $a_allow_dir = 
false   245         $i = count($this->commands);
   247         $this->commands[$i][
"object"] = $a_obj;
   248         $this->commands[$i][
"method"] = $a_func;
   249         $this->commands[$i][
"name"] = $a_name;
   250         $this->commands[$i][
"single"] = $a_single;
   251         $this->commands[$i][
"allow_dir"] = $a_allow_dir;
   256         $this->commands = [];
   259     public function labelFile(
string $a_file, 
string $a_label): void
   261         $this->file_labels[$a_file][] = $a_label;
   266         $this->label_enable = $a_act;
   267         $this->label_header = $a_label_header;
   280         $cur_subdir = $this->wrapper->query()->has(self::PARAMETER_CDIR)
   281             ? $this->wrapper->query()->retrieve(self::PARAMETER_CDIR, $this->
refinery->to()->string())
   284         $new_subdir = $this->wrapper->query()->has(self::PARAMETER_NEWDIR)
   285             ? $this->wrapper->query()->retrieve(self::PARAMETER_NEWDIR, $this->
refinery->to()->string())
   291         if ($new_subdir === 
"..") {
   292             $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, 
"/"));
   294             if (!empty($new_subdir)) {
   295                 if (!empty($cur_subdir)) {
   296                     $cur_subdir = $cur_subdir . 
"/" . $new_subdir;
   298                     $cur_subdir = $new_subdir;
   303         $cur_subdir = str_replace(
"..", 
"", $cur_subdir);
   304         $cur_dir = (!empty($cur_subdir))
   305             ? $this->main_absolute_dir . 
"/" . $cur_subdir
   306             : $this->main_absolute_dir;
   309             "dir" => realpath($cur_dir),
   310             "subdir" => $cur_subdir
   317     protected function getFileList(
string $a_dir, ?
string $a_subdir = null): array
   321         $entries = (is_dir($a_dir))
   323             : array(array(
"type" => 
"dir", 
"entry" => 
".."));
   326         foreach ($entries as 
$e) {
   327             if (($e[
"entry"] == 
".") ||
   328                 ($e[
"entry"] == 
".." && empty($a_subdir))) {
   332             $cfile = (!empty($a_subdir))
   333                 ? $a_subdir . 
"/" . $e[
"entry"]
   337                 self::POST_PARAM_FILE => $cfile,
   338                 "entry" => $e[
"entry"],
   339                 "type" => $e[
"type"],
   340                 "size" => $e[
"size"] ?? 0,
   341                 "hash" => md5($e[
"entry"])
   353         $sel_files = $hashes = [];
   354         if ($this->wrapper->post()->has(self::POST_PARAM_FILE)) {
   355             $hashes = $this->wrapper->post()->retrieve(
   356                 self::POST_PARAM_FILE,
   361         } elseif ($this->wrapper->query()->has(self::PARAMETER_FHSH)) {
   362             $hashes = [$this->wrapper->query()->retrieve(
   363                 self::PARAMETER_FHSH,
   369         if (count($hashes) > 0) {
   371             $all_files = $this->
getFileList($dir[
"dir"], $dir[
"subdir"]);
   372             foreach ($hashes as $hash) {
   373                 foreach ($all_files as $file) {
   374                     if ($file[
"hash"] == $hash) {
   376                             ? $file[self::POST_PARAM_FILE]
   391         if (!count($selected)) {
   392             $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"no_checkbox"), 
true);
   393             $this->
ctrl->redirect($this, 
"listFiles");
   397         if (count($selected) > 1 && ($this->commands[$a_nr][
"single"] ?? 
false)) {
   398             $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"cont_select_max_one_item"), 
true);
   399             $this->
ctrl->redirect($this, 
"listFiles");
   406         foreach ($selected as $file) {
   408             $file = (!empty($cur_subdir))
   409                 ? $cur_subdir . 
"/" . $file
   413             if (is_dir($this->main_absolute_dir . 
"/" . $file) &&
   414                 !$this->commands[$a_nr][
"allow_dir"]) {
   415                 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"select_a_file"), 
true);
   416                 $this->
ctrl->redirect($this, 
"listFiles");
   422         if ($this->commands[$a_nr][
"single"] ?? 
false) {
   423             $files = array_shift($files);
   426         $obj = $this->commands[$a_nr][
"object"];
   427         $method = $this->commands[$a_nr][
"method"];
   429         return (
string) $obj->$method($files);
   434         $this->directory_creation = $a_val;
   447         $this->file_creation = $a_val;
   458         $ilToolbar = $DIC[
'ilToolbar'];
   460         $ilCtrl = $DIC[
'ilCtrl'];
   464         $this->
ctrl->setParameter($this, self::PARAMETER_CDIR, $dir[
"subdir"]);
   467         $ilToolbar->setFormAction($ilCtrl->getFormAction($this), 
true);
   470             $ti = 
new ilTextInputGUI($this->
lng->txt(
"cont_new_dir"), self::POST_PARAM_NEW_DIR);
   471             $ti->setMaxLength(80);
   473             $ilToolbar->addInputItem($ti, 
true);
   474             $ilToolbar->addFormButton($lng->
txt(
"create"), 
"createDirectory");
   476             $ilToolbar->addSeparator();
   481             $ilToolbar->addInputItem($fi, 
true);
   482             $ilToolbar->addFormButton($lng->
txt(
"upload"), 
"uploadFile");
   485             $ilToolbar->addSeparator();
   487             $options[
""] = $lng->
txt(
"cont_select_from_upload_dir");
   488             foreach ($files as $file) {
   489                 $file = htmlspecialchars($file, ENT_QUOTES, 
"utf-8");
   490                 $options[$file] = $file;
   492             $si = 
new ilSelectInputGUI($this->
lng->txt(
"cont_uploaded_file"), self::POST_PARAM_UPLOADED_FILE);
   494             $ilToolbar->addInputItem($si, 
true);
   495             $ilToolbar->addFormButton($lng->
txt(
"copy"), 
"uploadFile");
   498         $fs_table = $this->
getTable($dir[
"dir"], $dir[
"subdir"]);
   501             $fs_table->setTitle($this->
getTitle());
   504             $this->wrapper->query()->has(self::PARAM_RESETOFFSET)
   505             && $this->wrapper->query()->retrieve(
   506                 self::PARAM_RESETOFFSET,
   509             $fs_table->resetOffset();
   511         $this->tpl->setContent($fs_table->getHTML());
   533         $file = $this->main_absolute_dir . 
"/" . $a_file;
   535         $this->
ctrl->setParameter($this, self::PARAM_OLD_NAME, basename($a_file));
   536         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   541         $ti->setMaxLength(200);
   543         $ti->setValue(basename($a_file));
   547         $form->addCommandButton(
"renameFile", $this->
lng->txt(
"rename"));
   548         $form->addCommandButton(
"cancelRename", $this->
lng->txt(
"cancel"));
   549         $form->setFormAction($this->
ctrl->getFormAction($this, 
"renameFile"));
   552             $form->setTitle($this->
lng->txt(
"cont_rename_dir"));
   554             $form->setTitle($this->
lng->txt(
"rename_file"));
   557         $this->tpl->setContent($form->getHTML());
   562         $new_name = $this->wrapper->post()->has(self::POST_PARAM_NEW_NAME)
   563             ? $this->wrapper->post()->retrieve(self::POST_PARAM_NEW_NAME, $this->
refinery->to()->string())
   567         $new_name = str_replace(
"/", 
"", $new_name);
   568         if ($new_name === 
"") {
   572         $pi = pathinfo($new_name);
   573         $suffix = $pi[
"extension"] ?? 
"";
   575             $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"file_no_valid_file_type") . 
" ($suffix)", 
true);
   576             $this->
ctrl->redirect($this, 
"listFiles");
   580         $dir = (!empty($cur_subdir))
   581             ? $this->main_absolute_dir . 
"/" . $cur_subdir . 
"/"   582             : $this->main_absolute_dir . 
"/";
   584         $old_name = $this->wrapper->query()->has(self::PARAM_OLD_NAME)
   585             ? $this->wrapper->query()->retrieve(self::PARAM_OLD_NAME, $this->
refinery->to()->string())
   590         $realpath = realpath($dir . $old_name);
   591         if (strpos($realpath, realpath($dir)) !== 0) {
   595         if (is_dir($dir . $old_name)) {
   596             rename($dir . $old_name, $dir . $new_name);
   601                 $this->tpl->setOnScreenMessage(
'failure', $e->getMessage(), 
true);
   602                 $this->
ctrl->redirect($this, 
"listFiles");
   607         if (is_dir($dir . $new_name)) {
   608             $this->tpl->setOnScreenMessage(
   610                 $this->
lng->txt(
"cont_dir_renamed"),
   614                                                       self::POST_PARAM_NEW_NAME => $new_name
   617             $this->tpl->setOnScreenMessage(
   619                 $this->
lng->txt(
"cont_file_renamed"),
   623                                                             self::POST_PARAM_NEW_NAME => $new_name
   626         $this->
ctrl->redirect($this, 
"listFiles");
   631         $this->
ctrl->redirect($this, 
"listFiles");
   641         $cur_dir = (!empty($cur_subdir))
   642             ? $this->main_absolute_dir . 
"/" . $cur_subdir
   643             : $this->main_absolute_dir;
   645         $new_dir = $this->wrapper->post()->has(self::POST_PARAM_NEW_DIR)
   646             ? $this->wrapper->post()->retrieve(self::POST_PARAM_NEW_DIR, $this->
refinery->to()->string())
   650         $new_dir = str_replace(
"/", 
"", $new_dir);
   652         if (!empty($new_dir)) {
   654             if (is_dir($cur_dir . 
"/" . $new_dir)) {
   655                 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
"cont_dir_created"), 
true);
   659             $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
"cont_enter_a_dir_name"), 
true);
   661         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   662         $this->
ctrl->redirect($this, 
'listFiles');
   672         $cur_dir = (!empty($cur_subdir))
   673             ? $this->main_absolute_dir . 
"/" . $cur_subdir
   674             : $this->main_absolute_dir;
   678         $pi = pathinfo($_FILES[
"new_file"][
"name"]);
   679         $suffix = $pi[
"extension"] ?? 
"";
   681             $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"file_no_valid_file_type") . 
" ($suffix)", 
true);
   682             $this->
ctrl->redirect($this, 
"listFiles");
   685         $uploaded_file = $this->wrapper->post()->has(self::POST_PARAM_UPLOADED_FILE)
   686             ? $this->wrapper->post()->retrieve(self::POST_PARAM_UPLOADED_FILE, $this->
refinery->to()->string())
   688         if (is_file($_FILES[
"new_file"][
"tmp_name"])) {
   690             $tgt_file = $cur_dir . 
"/" . $name;
   694             $upload = $DIC->upload();
   697             if (!$upload->hasBeenProcessed()) {
   702             if (!$upload->hasUploads()) {
   704                     $DIC->language()->txt(
"upload_error_file_not_found")
   707             $upload_result = $upload->getResults()[$_FILES[
"new_file"][
"tmp_name"]];
   709                 $processing_status = $upload_result->getStatus();
   710                 if ($processing_status->getCode() === ProcessingStatus::REJECTED) {
   711                     $this->tpl->setOnScreenMessage(
   713                         $processing_status->getMessage(),
   716                     $this->
ctrl->redirect($this, 
"listFiles");
   720             $upload->moveOneFileTo(
   722                 LegacyPathHelper::createRelativePath($cur_dir . 
"/"),
   723                 LegacyPathHelper::deriveLocationFrom($cur_dir),
   728         } elseif ($uploaded_file) {
   736         } elseif (trim($_FILES[
"new_file"][
"name"]) == 
"") {
   737             $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
"cont_enter_a_file"), 
true);
   740         if ($tgt_file && is_file($tgt_file)) {
   742             if (MimeType::getMimeType($tgt_file) == 
"application/zip") {
   743                 $this->
ctrl->setParameter($this, self::PARAM_UPFILE, basename($tgt_file));
   744                 $url = $this->
ctrl->getLinkTarget($this, self::CMD_UNZIP_FILE);
   745                 $this->
ctrl->setParameter($this, self::PARAM_UPFILE, 
"");
   747                 $unzip_link = $this->ui_factory->link()->standard(
   748                     $this->
lng->txt(
"unzip"),
   752                 $unzip = 
" " . $this->ui_renderer->render($unzip_link);
   755             $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
"cont_file_created") . 
$unzip, 
true);
   759                 array(
"name" => substr($tgt_file, strlen($this->main_absolute_dir) + 1))
   763         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   767         $this->
ctrl->redirect($this, 
'listFiles');
   773         $ilCtrl = $DIC[
'ilCtrl'];
   778         $cgui->setFormAction($ilCtrl->getFormAction($this));
   779         $cgui->setHeaderText($lng->
txt(
"info_delete_sure"));
   780         $cgui->setCancel($lng->
txt(
"cancel"), 
"listFiles");
   781         $cgui->setConfirm($lng->
txt(
"delete"), 
"deleteFile");
   783         foreach ($a_files as $i) {
   784             $cgui->addItem(
"file[]", $i, $i);
   792         if (!$this->wrapper->post()->has(self::POST_PARAM_FILE)) {
   798         $postfiles = $this->wrapper->post()->retrieve(
   799             self::POST_PARAM_FILE,
   804         foreach ($postfiles as $post_file) {
   811             $cur_dir = (!empty($cur_subdir))
   812                 ? $this->main_absolute_dir . 
"/" . $cur_subdir
   813                 : $this->main_absolute_dir;
   814             $pi = pathinfo($post_file);
   817             if (is_file($file)) {
   827         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   829             $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"cont_dir_deleted"), 
true);
   835             $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"cont_file_deleted"), 
true);
   841         $this->
ctrl->redirect($this, 
'listFiles');
   847         $upname = $this->wrapper->query()->has(self::PARAM_UPFILE)
   848             ? $this->wrapper->query()->retrieve(self::PARAM_UPFILE, $this->
refinery->to()->string())
   850         if (is_null($a_file) && $upname !== null) {
   851             $a_file = basename($upname);
   855         $cur_dir = (!empty($cur_subdir))
   856             ? $this->main_absolute_dir . 
"/" . $cur_subdir
   857             : $this->main_absolute_dir;
   858         $a_file = $this->main_absolute_dir . 
"/" . $a_file;
   860         if (is_file($a_file)) {
   875             $diff = array_diff($new_files, $cur_files);
   876             $diff_r = array_diff($new_files_r, $cur_files_r);
   879             foreach ($diff_r as 
$f => 
$d) {
   881                 if (!is_dir(
$f) && !$this->
isValidSuffix(strtolower($pi[
"extension"] ?? 
''))) {
   882                     $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"file_some_invalid_file_types_removed") . 
" (" . $pi[
"extension"] . 
")", 
true);
   889                     $new_files = array();
   891                     foreach ($diff as $new_item) {
   892                         if (is_dir($cur_dir . 
"/" . $new_item)) {
   897                     if (isset($new_files[
"path"])) {
   898                         foreach ($new_files[
"path"] as $idx => 
$path) {
   899                             $path = substr(
$path, strlen($this->main_absolute_dir) + 1);
   900                             $diff[] = 
$path . $new_files[self::POST_PARAM_FILE][$idx];
   907                     array(
"added" => $diff
   915         $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   916         $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"cont_file_unzipped"), 
true);
   917         $this->
ctrl->redirect($this, 
"listFiles");
   922         $file = $this->main_absolute_dir . 
"/" . $a_file;
   924         if (is_file($file) && !(is_dir($file))) {
   928             $this->
ctrl->saveParameter($this, self::PARAMETER_CDIR);
   929             $this->
ctrl->redirect($this, 
"listFiles");
   943         $this->commands = array(
   946                 "method" => 
"downloadFile",
   947                 "name" => $this->
lng->txt(
"download"),
   953                 "method" => 
"confirmDeleteFile",
   954                 "name" => $this->
lng->txt(
"delete"),
   960                 "method" => self::CMD_UNZIP_FILE,
   961                 "name" => $this->
lng->txt(
"unzip"),
   968                 "method" => 
"renameFileForm",
   969                 "name" => $this->
lng->txt(
"rename"),
   979         $cur_subdir = $this->wrapper->query()->has(self::PARAMETER_CDIR)
   980             ? $this->wrapper->query()->retrieve(self::PARAMETER_CDIR, $this->
refinery->to()->string())
 const SESSION_LAST_COMMAND
 
static get(string $a_var)
 
activateLabels(bool $a_act, string $a_label_header)
 
ILIAS HTTP Wrapper WrapperFactory $wrapper
 
static _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors=true)
 
downloadFile(string $a_file)
 
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
 
renameFileForm(string $a_file)
 
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
 
ilGlobalTemplateInterface $tpl
 
getAllowDirectoryCreation()
 
const POST_PARAM_UPLOADED_FILE
 
static _getUploadDirectory()
 
addCommand(object $a_obj, string $a_func, string $a_name, bool $a_single=true, bool $a_allow_dir=false)
 
setAllowDirectoryCreation(bool $a_val)
 
listFiles(?ilTable2GUI $a_table_gui=null)
 
getLastPerformedCommand()
 
bool $use_upload_directory
 
getTable(string $a_dir, string $a_subdir)
 
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
 
static renameExecutables(string $a_dir)
 
isValidSuffix(string $a_suffix)
 
ILIAS Filesystem Util Archive LegacyArchives $unzip
 
__construct(string $main_absolute_directory)
 
sanitizeCurrentDirectory()
 
setContent(string $a_html)
Sets content for standard template. 
 
setAllowedSuffixes(array $a_suffixes)
 
static recursive_dirscan(string $dir, array &$arr)
Recursively scans a given directory and writes path and filename into referenced array. 
 
array $forbidden_suffixes
 
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively 
 
setUseUploadDirectory(bool $a_val)
 
const POST_PARAM_NEW_NAME
 
setAllowDirectories(bool $a_val)
 
ILIAS UI Factory $ui_factory
 
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory 
 
labelFile(string $a_file, string $a_label)
 
getFileList(string $a_dir, ?string $a_subdir=null)
 
setPostDirPath(bool $a_val)
 
ILIAS UI Renderer $ui_renderer
 
static _checkUploadFile(string $a_file)
 
setPerformedCommand($command, array $pars=[])
 
setForbiddenSuffixes(array $a_suffixes)
 
ILIAS Refinery Factory $refinery
 
confirmDeleteFile(array $a_files)
 
static rename(string $a_source, string $a_target)
 
File System Explorer GUI class. 
 
string $main_absolute_dir
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static set(string $a_var, $a_val)
Set a value. 
 
setAllowFileCreation(bool $a_val)
Set allowed file creation. 
 
unzipFile(?string $a_file=null)
 
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
 
setTableId(string $a_val)