ILIAS  release_7 Revision v7.30-3-g800a261c036
ilUploadFiles Class Reference
+ Collaboration diagram for ilUploadFiles:

Static Public Member Functions

static _getUploadDirectory ()
 Get the directory with uploaded files. More...
 
static _getUploadFiles ()
 Get a list of readable files in the upload directory. More...
 
static _checkUploadFile ($a_file)
 Check if a file exists in the upload directory and is readable. More...
 
static _copyUploadFile ($a_file, $a_target, $a_raise_errors=true)
 copy an uploaded file to the target directory (including virus check) More...
 

Detailed Description

Member Function Documentation

◆ _checkUploadFile()

static ilUploadFiles::_checkUploadFile (   $a_file)
static

Check if a file exists in the upload directory and is readable.

Parameters
stringfile name
Returns
boolean true/false @access static

Definition at line 103 of file class.ilUploadFiles.php.

104 {
105 $files = self::_getUploadFiles();
106
107 return in_array($a_file, $files);
108 }
static _getUploadFiles()
Get a list of readable files in the upload directory.

References _getUploadFiles().

Referenced by ilObjCmiXapiGUI\afterSave(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilFileSystemGUI\uploadFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _copyUploadFile()

static ilUploadFiles::_copyUploadFile (   $a_file,
  $a_target,
  $a_raise_errors = true 
)
static

copy an uploaded file to the target directory (including virus check)

Parameters
stringfile name
stringtarget path and name
Returns
boolean true/false @access static

Definition at line 118 of file class.ilUploadFiles.php.

119 {
120 global $DIC;
121 $lng = $DIC['lng'];
122 $ilias = $DIC['ilias'];
123
124 $file = self::_getUploadDirectory() . "/" . $a_file;
125
126 // check if file exists
127 if (!is_file($file)) {
128 if ($a_raise_errors) {
129 $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
130 } else {
131 ilUtil::sendFailure($lng->txt("upload_error_file_not_found"), true);
132 }
133 return false;
134 }
135
136 // virus handling
137 $vir = ilUtil::virusHandling($file, $a_file);
138 if (!$vir[0]) {
139 if ($a_raise_errors) {
140 $ilias->raiseError(
141 $lng->txt("file_is_infected") . "<br />" .
142 $vir[1],
143 $ilias->error_obj->MESSAGE
144 );
145 } else {
146 ilUtil::sendFailure($lng->txt("file_is_infected") . "<br />" .
147 $vir[1], true);
148 }
149 return false;
150 } else {
151 if ($vir[1] != "") {
152 ilUtil::sendInfo($vir[1], true);
153 }
154 return copy($file, $a_target);
155 }
156 }
static _getUploadDirectory()
Get the directory with uploaded files.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
$lng

References $DIC, $lng, _getUploadDirectory(), ilUtil\sendFailure(), ilUtil\sendInfo(), and ilUtil\virusHandling().

Referenced by ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilFileSystemGUI\uploadFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getUploadDirectory()

static ilUploadFiles::_getUploadDirectory ( )
static

Get the directory with uploaded files.

The directory is configured as cont_upload_dir in the settings table. The directory must exist and have read permissions. Currently the user must have admin permissions in ILIAS. Later there may be different directories for different users/roles.

Returns
string full path of upload directory on the server or empty @access static

Definition at line 46 of file class.ilUploadFiles.php.

47 {
48 global $DIC;
49 $rbacsystem = $DIC['rbacsystem'];
50
51 if (!$rbacsystem->checkAccess('write', SYSTEM_FOLDER_ID)) {
52 return '';
53 }
54
55 $lm_set = new ilSetting("lm");
56 $upload_dir = $lm_set->get("cont_upload_dir");
57
58 $web_directory = $DIC->filesystem()->storage();
59 $import_file_factory = new ilImportDirectoryFactory($web_directory);
60 try {
61 $scorm_import_directory = $import_file_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_SAHS);
62 } catch (InvalidArgumentException $e) {
63 return '';
64 }
65 return $scorm_import_directory->getAbsolutePath();
66 }
ILIAS Setting Class.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
$lm_set

References $DIC, Vendor\Package\$e, $lm_set, SYSTEM_FOLDER_ID, and ilImportDirectoryFactory\TYPE_SAHS.

Referenced by _copyUploadFile(), ilObjCmiXapiGUI\afterSave(), ilObjCmiXapiGUI\initCreateForm(), ilObjSAHSLearningModuleGUI\initUploadForm(), ilFileSystemGUI\listFiles(), and ilObjSCORMLearningModuleGUI\newModuleVersion().

+ Here is the caller graph for this function:

◆ _getUploadFiles()

static ilUploadFiles::_getUploadFiles ( )
static

Get a list of readable files in the upload directory.

Returns
array list of file names (without path) @access static

Definition at line 74 of file class.ilUploadFiles.php.

75 {
76 if (!$upload_dir = self::_getUploadDirectory()) {
77 return array();
78 }
79
80 // get the sorted content of the upload directory
81 $handle = opendir($upload_dir);
82 $files = array();
83 while (false !== ($file = readdir($handle))) {
84 $full_path = $upload_dir . "/" . $file;
85 if (is_file($full_path) and is_readable($full_path)) {
86 $files[] = $file;
87 }
88 }
89 closedir($handle);
90 sort($files);
91 reset($files);
92
93 return $files;
94 }

Referenced by _checkUploadFile(), ilObjCmiXapiGUI\initCreateForm(), ilObjSAHSLearningModuleGUI\initUploadForm(), ilFileSystemGUI\listFiles(), and ilObjSCORMLearningModuleGUI\newModuleVersion().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: