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