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