ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  *****************************************************************************/
20 {
21  public static function _getUploadDirectory(): string
22  {
23  global $DIC;
24  $rbacsystem = $DIC['rbacsystem'];
25 
26  if (!$rbacsystem->checkAccess('write', SYSTEM_FOLDER_ID)) {
27  return '';
28  }
29 
30  $lm_set = new ilSetting("lm");
31  $upload_dir = $lm_set->get("cont_upload_dir");
32 
33  $import_file_factory = new ilImportDirectoryFactory();
34  try {
35  $scorm_import_directory = $import_file_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_SAHS);
36  } catch (InvalidArgumentException $e) {
37  return '';
38  }
39  return $scorm_import_directory->getAbsolutePath();
40  }
41 
45  public static function _getUploadFiles(): array
46  {
47  if (!$upload_dir = self::_getUploadDirectory()) {
48  return array();
49  }
50 
51  // get the sorted content of the upload directory
52  $handle = opendir($upload_dir);
53  $files = array();
54  while (false !== ($file = readdir($handle))) {
55  $full_path = $upload_dir . "/" . $file;
56  if (is_file($full_path) and is_readable($full_path)) {
57  $files[] = $file;
58  }
59  }
60  closedir($handle);
61  sort($files);
62 
63  return $files;
64  }
65 
66  public static function _checkUploadFile(string $a_file): bool
67  {
68  $files = self::_getUploadFiles();
69 
70  return in_array($a_file, $files);
71  }
72 
73  public static function _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors = true): bool
74  {
75  global $DIC;
76  $main_tpl = $DIC->ui()->mainTemplate();
77  $lng = $DIC['lng'];
78  $ilias = $DIC['ilias'];
79 
80  $file = self::_getUploadDirectory() . "/" . $a_file;
81 
82  // check if file exists
83  if (!is_file($file)) {
84  if ($a_raise_errors) {
85  $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
86  } else {
87  $main_tpl->setOnScreenMessage('failure', $lng->txt("upload_error_file_not_found"), true);
88  }
89  return false;
90  }
91 
92  // virus handling
93  $vir = ilVirusScanner::virusHandling($file, $a_file);
94  if (!$vir[0]) {
95  if ($a_raise_errors) {
96  $ilias->raiseError(
97  $lng->txt("file_is_infected") . "<br />" .
98  $vir[1],
99  $ilias->error_obj->MESSAGE
100  );
101  } else {
102  $main_tpl->setOnScreenMessage('failure', $lng->txt("file_is_infected") . "<br />" .
103  $vir[1], true);
104  }
105  return false;
106  } else {
107  if ($vir[1] != "") {
108  $main_tpl->setOnScreenMessage('info', $vir[1], true);
109  }
110  return copy($file, $a_target);
111  }
112  }
113 }
static _copyUploadFile(string $a_file, string $a_target, bool $a_raise_errors=true)
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
static _getUploadDirectory()
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$lng
$lm_set
static _checkUploadFile(string $a_file)