ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  static function _getUploadDirectory()
47  {
48  global $rbacsystem;
49 
50  if(!$rbacsystem->checkAccess('write', SYSTEM_FOLDER_ID))
51  {
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  {
60  return $upload_dir;
61  }
62  else
63  {
64  return '';
65  }
66  }
67 
74  static function _getUploadFiles()
75  {
76  if (!$upload_dir = self::_getUploadDirectory())
77  {
78  return array();
79  }
80 
81  // get the sorted content of the upload directory
82  $handle = opendir($upload_dir);
83  $files = array();
84  while (false !== ($file = readdir($handle)))
85  {
86  $full_path = $upload_dir . "/". $file;
87  if (is_file($full_path) and is_readable($full_path))
88  {
89  $files[] = $file;
90  }
91  }
92  closedir($handle);
93  sort($files);
94  reset($files);
95 
96  return $files;
97  }
98 
106  static function _checkUploadFile($a_file)
107  {
108  $files = self::_getUploadFiles();
109 
110  return in_array($a_file, $files);
111  }
112 
121  static function _copyUploadFile($a_file, $a_target, $a_raise_errors = true)
122  {
123  global $lng, $ilias;
124 
125  $file = self::_getUploadDirectory() . "/". $a_file;
126 
127  // check if file exists
128  if (!is_file($file))
129  {
130  if ($a_raise_errors)
131  {
132  $ilias->raiseError($lng->txt("upload_error_file_not_found"), $ilias->error_obj->MESSAGE);
133  }
134  else
135  {
136  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"), true);
137  }
138  return false;
139  }
140 
141  // virus handling
142  $vir = ilUtil::virusHandling($file, $a_file);
143  if (!$vir[0])
144  {
145  if ($a_raise_errors)
146  {
147  $ilias->raiseError($lng->txt("file_is_infected")."<br />".
148  $vir[1],
149  $ilias->error_obj->MESSAGE);
150  }
151  else
152  {
153  ilUtil::sendFailure($lng->txt("file_is_infected")."<br />".
154  $vir[1], true);
155  }
156  return false;
157  }
158  else
159  {
160  if ($vir[1] != "")
161  {
162  ilUtil::sendInfo($vir[1], true);
163  }
164  return copy($file, $a_target);
165  }
166  }
167 
168 }
169 
170 ?>