ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUploadFiles.php
Go to the documentation of this file.
1<?php
2
24{
25 public static function _getUploadDirectory(): string
26 {
27 global $DIC;
28 $rbacsystem = $DIC['rbacsystem'];
29
30 if (!$rbacsystem->checkAccess('write', SYSTEM_FOLDER_ID)) {
31 return '';
32 }
33
34 $lm_set = new ilSetting("lm");
35 $upload_dir = $lm_set->get("cont_upload_dir");
36
37 $import_file_factory = new ilImportDirectoryFactory();
38 try {
39 $scorm_import_directory = $import_file_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_SAHS);
40 } catch (InvalidArgumentException) {
41 return '';
42 }
43 return $scorm_import_directory->getAbsolutePath();
44 }
45
49 public static function _getUploadFiles(): array
50 {
51 if ($upload_dir = self::_getUploadDirectory() === '' || $upload_dir = self::_getUploadDirectory() === '0') {
52 return [];
53 }
54
55 // get the sorted content of the upload directory
56 $handle = opendir($upload_dir);
57 $files = [];
58 while (false !== ($file = readdir($handle))) {
59 $full_path = $upload_dir . "/" . $file;
60 if (is_file($full_path) && is_readable($full_path)) {
61 $files[] = $file;
62 }
63 }
64 closedir($handle);
65 sort($files);
66
67 return $files;
68 }
69
70 public static function _checkUploadFile(string $a_file): bool
71 {
72 $files = self::_getUploadFiles();
73
74 return in_array($a_file, $files);
75 }
76
77 public static function _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors = true): bool
78 {
79 global $DIC;
80 $main_tpl = $DIC->ui()->mainTemplate();
81 $lng = $DIC['lng'];
82 $ilias = $DIC['ilias'];
83
84 $file = self::_getUploadDirectory() . "/" . $a_file;
85
86 // check if file exists
87 if (!is_file($file)) {
88 if ($a_raise_errors) {
89 $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
90 } else {
91 $main_tpl->setOnScreenMessage('failure', $lng->txt("upload_error_file_not_found"), true);
92 }
93 return false;
94 }
95
96 // virus handling
97 $vir = ilVirusScanner::virusHandling($file, $a_file);
98 if (!$vir[0]) {
99 if ($a_raise_errors) {
100 $ilias->raiseError(
101 $lng->txt("file_is_infected") . "<br />" .
102 $vir[1],
103 $ilias->error_obj->MESSAGE
104 );
105 } else {
106 $main_tpl->setOnScreenMessage('failure', $lng->txt("file_is_infected") . "<br />" .
107 $vir[1], true);
108 }
109 return false;
110 }
111 if ($vir[1] != "") {
112 $main_tpl->setOnScreenMessage('info', $vir[1], true);
113 }
114 return copy($file, $a_target);
115 }
116}
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors=true)
static _checkUploadFile(string $a_file)
static _getUploadDirectory()
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$lm_set