ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $upload_dir = self::_getUploadDirectory();
52 if ($upload_dir === '' || $upload_dir === '0') {
53 return [];
54 }
55
56 // get the sorted content of the upload directory
57 $handle = opendir($upload_dir);
58 $files = [];
59 while (false !== ($file = readdir($handle))) {
60 $full_path = $upload_dir . "/" . $file;
61 if (is_file($full_path) && is_readable($full_path)) {
62 $files[] = $file;
63 }
64 }
65 closedir($handle);
66 sort($files);
67
68 return $files;
69 }
70
71 public static function _checkUploadFile(string $a_file): bool
72 {
73 $files = self::_getUploadFiles();
74
75 return in_array($a_file, $files);
76 }
77
78 public static function _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors = true): bool
79 {
80 global $DIC;
81 $main_tpl = $DIC->ui()->mainTemplate();
82 $lng = $DIC['lng'];
83 $ilias = $DIC['ilias'];
84
85 $file = self::_getUploadDirectory() . "/" . $a_file;
86
87 // check if file exists
88 if (!is_file($file)) {
89 if ($a_raise_errors) {
90 $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
91 } else {
92 $main_tpl->setOnScreenMessage('failure', $lng->txt("upload_error_file_not_found"), true);
93 }
94 return false;
95 }
96
97 // virus handling
98 $vir = ilVirusScanner::virusHandling($file, $a_file);
99 if (!$vir[0]) {
100 if ($a_raise_errors) {
101 $ilias->raiseError(
102 $lng->txt("file_is_infected") . "<br />" .
103 $vir[1],
104 $ilias->error_obj->MESSAGE
105 );
106 } else {
107 $main_tpl->setOnScreenMessage('failure', $lng->txt("file_is_infected") . "<br />" .
108 $vir[1], true);
109 }
110 return false;
111 }
112 if ($vir[1] != "") {
113 $main_tpl->setOnScreenMessage('info', $vir[1], true);
114 }
115 return copy($file, $a_target);
116 }
117}
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