49 $ilCtrl = $DIC[
'ilCtrl'];
51 $ilias = $DIC[
'ilias'];
53 $this->ctrl = $ilCtrl;
55 $this->
ilias = $ilias;
57 $this->main_dir = $a_main_directory;
58 $this->post_dir_path =
false;
62 $this->file_labels = array();
63 $this->label_enable =
false;
64 $this->ctrl->saveParameter($this, self::CDIR);
65 $lng->loadLanguageModule(
"content");
79 $this->allowed_suffixes = $a_suffixes;
99 $this->forbidden_suffixes = $a_suffixes;
140 $this->allow_directories = $a_val;
150 return $this->allow_directories;
160 $this->post_dir_path = $a_val;
170 return $this->post_dir_path;
180 $this->table_id = $a_val;
190 return $this->table_id;
200 $this->title = $a_val;
220 $this->use_upload_directory = $a_val;
241 if (!is_array($pars)) {
244 $_SESSION[
"fsys"][
"lastcomm"] = array_merge(
245 array(
"cmd" => $command),
267 $next_class = $this->ctrl->getNextClass($this);
268 $cmd = $this->ctrl->getCmd(
"listFiles");
270 switch ($next_class) {
273 if (substr($cmd, 0, 11) ==
"extCommand_") {
276 $ret = $this->$cmd();
295 $i = count($this->commands);
297 $this->commands[
$i][
"object"] = $a_obj;
298 $this->commands[
$i][
"method"] = $a_func;
299 $this->commands[
$i][
"name"] = $a_name;
300 $this->commands[
$i][
"single"] = $a_single;
301 $this->commands[
$i][
"allow_dir"] = $a_allow_dir;
311 $this->commands = array();
319 $this->file_labels[$a_file][] = $a_label;
327 $this->label_enable = $a_act;
328 $this->label_header = $a_label_header;
342 if ($new_subdir ==
"..") {
343 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir,
"/"));
345 if (!empty($new_subdir)) {
346 if (!empty($cur_subdir)) {
347 $cur_subdir = $cur_subdir .
"/" . $new_subdir;
349 $cur_subdir = $new_subdir;
354 $cur_subdir = str_replace(
"..",
"", $cur_subdir);
355 $cur_dir = (!empty($cur_subdir))
356 ? $this->main_dir .
"/" . $cur_subdir
359 return array(
"dir" => $cur_dir,
"subdir" => $cur_subdir);
366 $entries = (is_dir($a_dir))
368 : array(array(
"type" =>
"dir",
"entry" =>
".."));
371 foreach ($entries as
$e) {
372 if (($e[
"entry"] ==
".") ||
373 ($e[
"entry"] ==
".." && empty($a_subdir))) {
377 $cfile = (!empty($a_subdir))
378 ? $a_subdir .
"/" . $e[
"entry"]
383 "entry" => $e[
"entry"],
384 "type" => $e[
"type"],
385 "size" => $e[
"size"],
386 "hash" => md5($e[
"entry"])
395 $sel_files = $hashes = array();
396 if (isset(
$_POST[
"file"])) {
398 } elseif (isset(
$_GET[
"fhsh"])) {
399 $hashes = array(
$_GET[
"fhsh"]);
402 if (
sizeof($hashes)) {
404 $all_files = $this->
getFileList($dir[
"dir"], $dir[
"subdir"]);
405 foreach ($hashes as $hash) {
406 foreach ($all_files as $file) {
407 if ($file[
"hash"] == $hash) {
427 if (!count($selected)) {
429 $this->ctrl->redirect($this,
"listFiles");
433 if (count($selected) > 1 && $this->commands[$a_nr][
"single"]) {
435 $this->ctrl->redirect($this,
"listFiles");
442 foreach ($selected as $file) {
444 $file = (!empty($cur_subdir))
445 ? $cur_subdir .
"/" . $file
449 if (@is_dir($this->main_dir .
"/" . $file) &&
450 !$this->commands[$a_nr][
"allow_dir"]) {
452 $this->ctrl->redirect($this,
"listFiles");
458 if ($this->commands[$a_nr][
"single"]) {
459 $files = array_shift($files);
462 $obj = $this->commands[$a_nr][
"object"];
463 $method = $this->commands[$a_nr][
"method"];
465 return $obj->$method($files);
473 $this->directory_creation = $a_val;
481 return $this->directory_creation;
489 $this->file_creation = $a_val;
497 return $this->file_creation;
509 $ilToolbar = $DIC[
'ilToolbar'];
511 $ilCtrl = $DIC[
'ilCtrl'];
515 $this->ctrl->setParameter($this, self::CDIR, $dir[
"subdir"]);
518 $ilToolbar->setFormAction($ilCtrl->getFormAction($this),
true);
519 include_once(
"./Services/Form/classes/class.ilTextInputGUI.php");
522 $ti =
new ilTextInputGUI($this->lng->txt(
"cont_new_dir"),
"new_dir");
523 $ti->setMaxLength(80);
525 $ilToolbar->addInputItem($ti,
true);
526 $ilToolbar->addFormButton(
$lng->txt(
"create"),
"createDirectory");
528 $ilToolbar->addSeparator();
531 include_once(
"./Services/Form/classes/class.ilFileInputGUI.php");
533 $fi =
new ilFileInputGUI($this->lng->txt(
"cont_new_file"),
"new_file");
535 $ilToolbar->addInputItem($fi,
true);
536 $ilToolbar->addFormButton(
$lng->txt(
"upload"),
"uploadFile");
539 include_once
'Services/FileSystem/classes/class.ilUploadFiles.php';
541 $ilToolbar->addSeparator();
543 $options[
""] =
$lng->txt(
"cont_select_from_upload_dir");
544 foreach ($files as $file) {
545 $file = htmlspecialchars($file, ENT_QUOTES,
"utf-8");
546 $options[$file] = $file;
548 include_once(
"./Services/Form/classes/class.ilSelectInputGUI.php");
550 $si->setOptions($options);
551 $ilToolbar->addInputItem(
$si,
true);
552 $ilToolbar->addFormButton(
$lng->txt(
"copy"),
"uploadFile");
555 $fs_table = $this->
getTable($dir[
"dir"], $dir[
"subdir"]);
558 $fs_table->setTitle($this->
getTitle());
560 if (
$_GET[
"resetoffset"] == 1) {
561 $fs_table->resetOffset();
563 $this->tpl->setContent($fs_table->getHTML());
574 include_once(
"./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
596 $ilCtrl = $DIC[
'ilCtrl'];
599 $file = $this->main_dir .
"/" . $a_file;
601 $this->ctrl->setParameter($this,
"old_name", basename($a_file));
604 include_once(
"Services/Form/classes/class.ilPropertyFormGUI.php");
609 $ti->setMaxLength(200);
611 $ti->setValue(basename($a_file));
615 $form->addCommandButton(
"renameFile",
$lng->txt(
"rename"));
616 $form->addCommandButton(
"cancelRename",
$lng->txt(
"cancel"));
617 $form->setFormAction($ilCtrl->getFormAction($this,
"renameFile"));
619 if (@is_dir($file)) {
620 $form->setTitle($this->lng->txt(
"cont_rename_dir"));
622 $form->setTitle($this->lng->txt(
"rename_file"));
625 $this->tpl->setContent($form->getHTML());
637 $new_name = str_replace(
"/",
"", $new_name);
638 if ($new_name ==
"") {
639 $this->
ilias->raiseError($this->lng->txt(
"enter_new_name"), $this->
ilias->error_obj->MESSAGE);
642 $pi = pathinfo($new_name);
643 $suffix = $pi[
"extension"];
646 $this->ctrl->redirect($this,
"listFiles");
650 $dir = (!empty($cur_subdir))
651 ? $this->main_dir .
"/" . $cur_subdir .
"/" 652 : $this->main_dir .
"/";
656 $realpath = realpath($dir . $old_name);
657 if (strpos($realpath, realpath($dir)) !== 0) {
658 $this->
ilias->raiseError($this->lng->txt(
"no_permission"), $this->
ilias->error_obj->MESSAGE);
661 if (is_dir($dir . $old_name)) {
662 rename($dir . $old_name, $dir . $new_name);
664 include_once(
"./Services/Utilities/classes/class.ilFileUtils.php");
670 $this->ctrl->redirect($this,
"listFiles");
675 if (@is_dir($dir . $new_name)) {
676 ilUtil::sendSuccess(
$lng->txt(
"cont_dir_renamed"),
true);
678 "new_name" => $new_name));
680 ilUtil::sendSuccess(
$lng->txt(
"cont_file_renamed"),
true);
682 "new_name" => $new_name));
684 $this->ctrl->redirect($this,
"listFiles");
692 $this->ctrl->redirect($this,
"listFiles");
705 $cur_dir = (!empty($cur_subdir))
706 ? $this->main_dir .
"/" . $cur_subdir
710 $new_dir = str_replace(
"/",
"", $new_dir);
712 if (!empty($new_dir)) {
714 if (is_dir($cur_dir .
"/" . $new_dir)) {
715 ilUtil::sendSuccess(
$lng->txt(
"cont_dir_created"),
true);
721 $this->ctrl->saveParameter($this, self::CDIR);
722 $this->ctrl->redirect($this,
'listFiles');
736 $cur_dir = (!empty($cur_subdir))
737 ? $this->main_dir .
"/" . $cur_subdir
742 $pi = pathinfo($_FILES[
"new_file"][
"name"]);
743 $suffix = $pi[
"extension"];
746 $this->ctrl->redirect($this,
"listFiles");
749 if (is_file($_FILES[
"new_file"][
"tmp_name"])) {
751 $tgt_file = $cur_dir .
"/" .
$name;
756 $this->ctrl->redirect($this,
"listFiles");
758 } elseif (
$_POST[
"uploaded_file"]) {
759 include_once
'Services/FileSystem/classes/class.ilUploadFiles.php';
768 } elseif (trim($_FILES[
"new_file"][
"name"]) ==
"") {
772 if ($tgt_file && is_file($tgt_file)) {
776 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
778 $this->ctrl->setParameter($this,
"upfile", basename($tgt_file));
779 $url = $this->ctrl->getLinkTarget($this,
"unzipFile");
780 $this->ctrl->setParameter($this,
"upfile",
"");
782 include_once
"Services/UIComponent/Button/classes/class.ilLinkButton.php";
784 $unzip->setCaption(
"unzip");
785 $unzip->setUrl(
$url);
786 $unzip =
" " . $unzip->render();
789 ilUtil::sendSuccess(
$lng->txt(
"cont_file_created") . $unzip,
true);
793 array(
"name" => substr($tgt_file, strlen($this->main_dir) + 1))
797 $this->ctrl->saveParameter($this, self::CDIR);
801 $this->ctrl->redirect($this,
'listFiles');
810 $ilCtrl = $DIC[
'ilCtrl'];
814 include_once(
"./Services/Utilities/classes/class.ilConfirmationGUI.php");
816 $cgui->setFormAction($ilCtrl->getFormAction($this));
817 $cgui->setHeaderText(
$lng->txt(
"info_delete_sure"));
818 $cgui->setCancel(
$lng->txt(
"cancel"),
"listFiles");
819 $cgui->setConfirm(
$lng->txt(
"delete"),
"deleteFile");
821 foreach ($a_files as
$i) {
822 $cgui->addItem(
"file[]", $i, $i);
825 $tpl->setContent($cgui->getHTML());
836 if (!isset(
$_POST[
"file"])) {
837 $this->
ilias->raiseError($this->lng->txt(
"no_checkbox"), $this->
ilias->error_obj->MESSAGE);
840 foreach (
$_POST[
"file"] as $post_file) {
842 $this->
ilias->raiseError($this->lng->txt(
"no_checkbox"), $this->
ilias->error_obj->MESSAGE);
847 $cur_dir = (!empty($cur_subdir))
848 ? $this->main_dir .
"/" . $cur_subdir
850 $pi = pathinfo($post_file);
853 if (@is_file($file)) {
857 if (@is_dir($file)) {
863 $this->ctrl->saveParameter($this, self::CDIR);
865 ilUtil::sendSuccess(
$lng->txt(
"cont_dir_deleted"),
true);
871 ilUtil::sendSuccess(
$lng->txt(
"cont_file_deleted"),
true);
877 $this->ctrl->redirect($this,
'listFiles');
890 isset(
$_GET[
"upfile"])) {
891 $a_file = basename(
$_GET[
"upfile"]);
895 $cur_dir = (!empty($cur_subdir))
896 ? $this->main_dir .
"/" . $cur_subdir
898 $a_file = $this->main_dir .
"/" . $a_file;
900 if (@is_file($a_file)) {
901 include_once(
"./Services/Utilities/classes/class.ilFileUtils.php");
914 $diff = array_diff($new_files, $cur_files);
915 $diff_r = array_diff($new_files_r, $cur_files_r);
918 foreach ($diff_r as
$f =>
$d) {
920 if (!is_dir(
$f) && !$this->
isValidSuffix(strtolower($pi[
"extension"]))) {
928 include_once(
"./Services/Utilities/classes/class.ilFileUtils.php");
929 $new_files = array();
931 foreach ($diff as $new_item) {
932 if (is_dir($cur_dir .
"/" . $new_item)) {
937 if (is_array($new_files[
"path"])) {
938 foreach ($new_files[
"path"] as $idx => $path) {
939 $path = substr($path, strlen($this->main_dir) + 1);
940 $diff[] = $path . $new_files[
"file"][$idx];
947 array(
"name" => substr($file, strlen($this->main_dir) + 1),
955 $this->ctrl->saveParameter($this, self::CDIR);
956 ilUtil::sendSuccess(
$lng->txt(
"cont_file_unzipped"),
true);
957 $this->ctrl->redirect($this,
"listFiles");
965 $file = $this->main_dir .
"/" . $a_file;
967 if (@is_file($file) && !(@is_dir($file))) {
971 $this->ctrl->saveParameter($this, self::CDIR);
972 $this->ctrl->redirect($this,
"listFiles");
982 $ilCtrl = $DIC[
'ilCtrl'];
984 $ilCtrl->setParameter($this,
"resetoffset", 1);
985 $tabs_gui->addTarget(
987 $this->ctrl->getLinkTarget($this,
"listFiles"),
991 $ilCtrl->setParameter($this,
"resetoffset",
"");
999 return $this->commands;
1007 $this->commands = array(
1010 "method" =>
"downloadFile",
1011 "name" => $this->lng->txt(
"download"),
1017 "method" =>
"confirmDeleteFile",
1018 "name" => $this->lng->txt(
"delete"),
1019 "allow_dir" =>
true,
1024 "method" =>
"unzipFile",
1025 "name" => $this->lng->txt(
"unzip"),
1031 "method" =>
"renameFileForm",
1032 "name" => $this->lng->txt(
"rename"),
1033 "allow_dir" =>
true,
1048 return str_replace(
"..",
"",
ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
downloadFile($a_file)
delete object file
listFiles($a_table_gui=null)
List files.
setTitle($a_val)
Set title.
activateLabels($a_act, $a_label_header)
activate file labels
getTableId()
Get table id.
setPostDirPath($a_val)
Set post dir path.
setAllowDirectories($a_val)
Set allow directories.
renameFileForm($a_file)
list files
getAllowDirectoryCreation()
Get allowed directory creation.
getForbiddenSuffixes()
Get Accepted Suffixes.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
addCommand(&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
Add command.
static _getUploadDirectory()
Get the directory with uploaded files.
static _getUploadFiles()
Get a list of readable files in the upload directory.
getAllowedSuffixes()
Get allowed Suffixes.
setUseUploadDirectory($a_val)
Set use upload directory.
getLastPerformedCommand()
Get performed command.
getTable($a_dir, $a_subdir)
Get table.
createDirectory()
create directory
clearCommands()
Clear commands.
static rename($a_source, $a_target)
Rename a file.
static getMimeType($a_file='', $a_filename='', $a_mime='')
setTableId($a_val)
Set table id.
setForbiddenSuffixes($a_suffixes)
Set forbidden Suffixes.
executeCommand()
execute command
getTabs(&$tabs_gui)
get tabs
sanitizeCurrentDirectory()
extCommand($a_nr)
call external command
deleteFile()
delete object file
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
getUseUploadDirectory()
Get use upload directory.
cancelRename()
cancel renaming a file
setAllowedSuffixes($a_suffixes)
Set allowed Suffixes.
renameFile()
rename a file
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
redirection script todo: (a better solution should control the processing via a xml file) ...
getAllowDirectories()
Get allow directories.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isValidSuffix($a_suffix)
Is suffix valid?
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
setAllowDirectoryCreation($a_val)
Set allowed directory creation.
__construct($a_main_directory)
defineCommands()
Define commands available.
getPostDirPath()
Get post dir path.
getFileList($a_dir, $a_subdir=null)
setAllowFileCreation($a_val)
Set allowed file creation.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
getAllowFileCreation()
Get allowed file creation.
confirmDeleteFile(array $a_files)
Confirm file deletion.
setPerformedCommand($command, $pars="")
Set performed command.
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
File System Explorer GUI class.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
labelFile($a_file, $a_label)
label a file
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
unzipFile($a_file=null)
delete object file
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Confirmation screen class.
TableGUI class for file system.