ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUploadFiles.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34{
46 public static function _getUploadDirectory()
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 }
67
74 public static function _getUploadFiles()
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 }
95
103 public static function _checkUploadFile($a_file)
104 {
105 $files = self::_getUploadFiles();
106
107 return in_array($a_file, $files);
108 }
109
118 public static function _copyUploadFile($a_file, $a_target, $a_raise_errors = true)
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 }
157}
An exception for terminatinating execution or to throw for unit testing.
ILIAS Setting Class.
static _getUploadFiles()
Get a list of readable files in the upload directory.
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
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.
const SYSTEM_FOLDER_ID
Definition: constants.php:33
global $DIC
Definition: goto.php:24
$lng
$lm_set