ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  if (is_dir($upload_dir) and is_readable($upload_dir)) {
59  return $upload_dir;
60  } else {
61  return '';
62  }
63  }
64 
71  public static function _getUploadFiles()
72  {
73  if (!$upload_dir = self::_getUploadDirectory()) {
74  return array();
75  }
76 
77  // get the sorted content of the upload directory
78  $handle = opendir($upload_dir);
79  $files = array();
80  while (false !== ($file = readdir($handle))) {
81  $full_path = $upload_dir . "/" . $file;
82  if (is_file($full_path) and is_readable($full_path)) {
83  $files[] = $file;
84  }
85  }
86  closedir($handle);
87  sort($files);
88  reset($files);
89 
90  return $files;
91  }
92 
100  public static function _checkUploadFile($a_file)
101  {
102  $files = self::_getUploadFiles();
103 
104  return in_array($a_file, $files);
105  }
106 
115  public static function _copyUploadFile($a_file, $a_target, $a_raise_errors = true)
116  {
117  global $DIC;
118  $lng = $DIC['lng'];
119  $ilias = $DIC['ilias'];
120 
121  $file = self::_getUploadDirectory() . "/" . $a_file;
122 
123  // check if file exists
124  if (!is_file($file)) {
125  if ($a_raise_errors) {
126  $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
127  } else {
128  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"), true);
129  }
130  return false;
131  }
132 
133  // virus handling
134  $vir = ilUtil::virusHandling($file, $a_file);
135  if (!$vir[0]) {
136  if ($a_raise_errors) {
137  $ilias->raiseError(
138  $lng->txt("file_is_infected") . "<br />" .
139  $vir[1],
140  $ilias->error_obj->MESSAGE
141  );
142  } else {
143  ilUtil::sendFailure($lng->txt("file_is_infected") . "<br />" .
144  $vir[1], true);
145  }
146  return false;
147  } else {
148  if ($vir[1] != "") {
149  ilUtil::sendInfo($vir[1], true);
150  }
151  return copy($file, $a_target);
152  }
153  }
154 }
$files
Definition: metarefresh.php:49
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
global $DIC
Definition: saml.php:7
static _getUploadDirectory()
Get the directory with uploaded files.
static _getUploadFiles()
Get a list of readable files in the upload directory.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$lng
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$lm_set
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)