ILIAS  release_8 Revision v8.24
class.ilUploadFiles.php
Go to the documentation of this file.
1<?php
2/******************************************************************************
3 *
4 * This file is part of ILIAS, a powerful learning management system.
5 *
6 * ILIAS is licensed with the GPL-3.0, you should have received a copy
7 * of said license along with the source code.
8 *
9 * If this is not the case or you just want to try ILIAS, you'll find
10 * us at:
11 * https://www.ilias.de
12 * https://github.com/ILIAS-eLearning
13 *
14 *****************************************************************************/
19{
20 public static function _getUploadDirectory(): string
21 {
22 global $DIC;
23 $rbacsystem = $DIC['rbacsystem'];
24
25 if (!$rbacsystem->checkAccess('write', SYSTEM_FOLDER_ID)) {
26 return '';
27 }
28
29 $lm_set = new ilSetting("lm");
30 $upload_dir = $lm_set->get("cont_upload_dir");
31
32 $import_file_factory = new ilImportDirectoryFactory();
33 try {
34 $scorm_import_directory = $import_file_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_SAHS);
35 } catch (InvalidArgumentException $e) {
36 return '';
37 }
38 return $scorm_import_directory->getAbsolutePath();
39 }
40
44 public static function _getUploadFiles(): array
45 {
46 if (!$upload_dir = self::_getUploadDirectory()) {
47 return array();
48 }
49
50 // get the sorted content of the upload directory
51 $handle = opendir($upload_dir);
52 $files = array();
53 while (false !== ($file = readdir($handle))) {
54 $full_path = $upload_dir . "/" . $file;
55 if (is_file($full_path) and is_readable($full_path)) {
56 $files[] = $file;
57 }
58 }
59 closedir($handle);
60 sort($files);
61
62 return $files;
63 }
64
65 public static function _checkUploadFile(string $a_file): bool
66 {
67 $files = self::_getUploadFiles();
68
69 return in_array($a_file, $files);
70 }
71
72 public static function _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors = true): bool
73 {
74 global $DIC;
75 $main_tpl = $DIC->ui()->mainTemplate();
76 $lng = $DIC['lng'];
77 $ilias = $DIC['ilias'];
78
79 $file = self::_getUploadDirectory() . "/" . $a_file;
80
81 // check if file exists
82 if (!is_file($file)) {
83 if ($a_raise_errors) {
84 $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
85 } else {
86 $main_tpl->setOnScreenMessage('failure', $lng->txt("upload_error_file_not_found"), true);
87 }
88 return false;
89 }
90
91 // virus handling
92 $vir = ilVirusScanner::virusHandling($file, $a_file);
93 if (!$vir[0]) {
94 if ($a_raise_errors) {
95 $ilias->raiseError(
96 $lng->txt("file_is_infected") . "<br />" .
97 $vir[1],
98 $ilias->error_obj->MESSAGE
99 );
100 } else {
101 $main_tpl->setOnScreenMessage('failure', $lng->txt("file_is_infected") . "<br />" .
102 $vir[1], true);
103 }
104 return false;
105 } else {
106 if ($vir[1] != "") {
107 $main_tpl->setOnScreenMessage('info', $vir[1], true);
108 }
109 return copy($file, $a_target);
110 }
111 }
112}
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 $DIC
Definition: feed.php:28
$lng
$lm_set