blob: 525880f62dd226a1b3db9de3c74f6c437894a711 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev3a459572011-12-21 11:23:11 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev3a459572011-12-21 11:23:11 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * File Uploading Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Uploads
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/libraries/file_uploading.html
37 */
38class CI_Upload {
Barry Mienydd671972010-10-04 16:33:58 +020039
Andrey Andreevf5ccd122012-11-02 00:17:39 +020040 /**
41 * Maximum file size
42 *
43 * @var int
44 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +030045 public $max_size = 0;
Andrey Andreevf5ccd122012-11-02 00:17:39 +020046
47 /**
48 * Maximum image width
49 *
50 * @var int
51 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +030052 public $max_width = 0;
Andrey Andreevf5ccd122012-11-02 00:17:39 +020053
54 /**
55 * Maximum image height
56 *
57 * @var int
58 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +030059 public $max_height = 0;
Andrey Andreevf5ccd122012-11-02 00:17:39 +020060
61 /**
Andrey Andreev05aa2d62012-12-03 16:06:55 +020062 * Minimum image width
63 *
64 * @var int
65 */
66 public $min_width = 0;
67
68 /**
69 * Minimum image height
70 *
71 * @var int
72 */
73 public $min_height = 0;
74
75 /**
Andrey Andreevf5ccd122012-11-02 00:17:39 +020076 * Maximum filename length
77 *
78 * @var int
79 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +030080 public $max_filename = 0;
Andrey Andreevf5ccd122012-11-02 00:17:39 +020081
82 /**
83 * Maximum duplicate filename increment ID
84 *
85 * @var int
86 */
Adam Jackettccbbea12011-08-21 16:19:11 -040087 public $max_filename_increment = 100;
Andrey Andreevf5ccd122012-11-02 00:17:39 +020088
89 /**
90 * Allowed file types
91 *
92 * @var string
93 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +030094 public $allowed_types = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +020095
96 /**
97 * Temporary filename
98 *
99 * @var string
100 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300101 public $file_temp = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200102
103 /**
104 * Filename
105 *
106 * @var string
107 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300108 public $file_name = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200109
110 /**
111 * Original filename
112 *
113 * @var string
114 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300115 public $orig_name = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200116
117 /**
118 * File type
119 *
120 * @var string
121 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300122 public $file_type = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200123
124 /**
125 * File size
126 *
127 * @var int
128 */
129 public $file_size = NULL;
130
131 /**
132 * Filename extension
133 *
134 * @var string
135 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300136 public $file_ext = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200137
138 /**
Adrianf496d132013-06-24 15:56:45 +0200139 * Force filename extension to lowercase
140 *
141 * @var string
142 */
Adrian74a228b2013-06-25 12:09:22 +0200143 public $file_ext_tolower = FALSE;
Adrianf496d132013-06-24 15:56:45 +0200144
145 /**
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200146 * Upload path
147 *
148 * @var string
149 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300150 public $upload_path = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200151
152 /**
153 * Overwrite flag
154 *
155 * @var bool
156 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300157 public $overwrite = FALSE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200158
159 /**
160 * Obfuscate filename flag
161 *
162 * @var bool
163 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300164 public $encrypt_name = FALSE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200165
166 /**
167 * Is image flag
168 *
169 * @var bool
170 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300171 public $is_image = FALSE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200172
173 /**
174 * Image width
175 *
176 * @var int
177 */
178 public $image_width = NULL;
179
180 /**
181 * Image height
182 *
183 * @var int
184 */
185 public $image_height = NULL;
186
187 /**
188 * Image type
189 *
190 * @var string
191 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300192 public $image_type = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200193
194 /**
195 * Image size string
196 *
197 * @var string
198 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300199 public $image_size_str = '';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200200
201 /**
202 * Error messages list
203 *
204 * @var array
205 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300206 public $error_msg = array();
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200207
208 /**
209 * MIME types list
210 *
211 * @var array
212 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300213 public $mimes = array();
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200214
215 /**
216 * Remove spaces flag
217 *
218 * @var bool
219 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300220 public $remove_spaces = TRUE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200221
222 /**
223 * MIME detection flag
224 *
225 * @var bool
226 */
Andrey Andreevd60e7002012-06-17 00:03:03 +0300227 public $detect_mime = TRUE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200228
229 /**
230 * XSS filter flag
231 *
232 * @var bool
233 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300234 public $xss_clean = FALSE;
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200235
236 /**
Andrey Andreev32c72122013-10-21 15:35:05 +0300237 * Apache mod_mime fix flag
238 *
239 * @var bool
240 */
241 public $mod_mime_fix = TRUE;
242
243 /**
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200244 * Temporary filename prefix
245 *
246 * @var string
247 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300248 public $temp_prefix = 'temp_file_';
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200249
250 /**
251 * Filename sent by the client
252 *
253 * @var bool
254 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300255 public $client_name = '';
Barry Mienydd671972010-10-04 16:33:58 +0200256
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200257 // --------------------------------------------------------------------
258
259 /**
260 * Filename override
261 *
262 * @var string
263 */
Greg Aker58fdee82010-11-10 15:07:09 -0600264 protected $_file_name_override = '';
Barry Mienydd671972010-10-04 16:33:58 +0200265
Andrey Andreev119d8a72014-01-08 15:27:53 +0200266 /**
267 * CI Singleton
268 *
269 * @var object
270 */
271 protected $CI;
272
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200273 // --------------------------------------------------------------------
274
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 /**
276 * Constructor
277 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200278 * @param array $props
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300279 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 */
Greg Aker58fdee82010-11-10 15:07:09 -0600281 public function __construct($props = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 {
283 if (count($props) > 0)
284 {
285 $this->initialize($props);
286 }
Barry Mienydd671972010-10-04 16:33:58 +0200287
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300288 $this->mimes =& get_mimes();
Andrey Andreev119d8a72014-01-08 15:27:53 +0200289 $this->CI =& get_instance();
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300290
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300291 log_message('debug', 'Upload Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 }
Barry Mienydd671972010-10-04 16:33:58 +0200293
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200295
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 /**
297 * Initialize preferences
298 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200299 * @param array $config
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200301 */
Greg Aker58fdee82010-11-10 15:07:09 -0600302 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 {
304 $defaults = array(
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300305 'max_size' => 0,
306 'max_width' => 0,
307 'max_height' => 0,
Andrey Andreev05aa2d62012-12-03 16:06:55 +0200308 'min_width' => 0,
309 'min_height' => 0,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300310 'max_filename' => 0,
311 'max_filename_increment' => 100,
312 'allowed_types' => '',
313 'file_temp' => '',
314 'file_name' => '',
315 'orig_name' => '',
316 'file_type' => '',
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200317 'file_size' => NULL,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300318 'file_ext' => '',
Adrian74a228b2013-06-25 12:09:22 +0200319 'file_ext_tolower' => FALSE,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300320 'upload_path' => '',
321 'overwrite' => FALSE,
322 'encrypt_name' => FALSE,
323 'is_image' => FALSE,
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200324 'image_width' => NULL,
325 'image_height' => NULL,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300326 'image_type' => '',
327 'image_size_str' => '',
328 'error_msg' => array(),
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300329 'remove_spaces' => TRUE,
Andrey Andreevd60e7002012-06-17 00:03:03 +0300330 'detect_mime' => TRUE,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300331 'xss_clean' => FALSE,
Andrey Andreev32c72122013-10-21 15:35:05 +0300332 'mod_mime_fix' => TRUE,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300333 'temp_prefix' => 'temp_file_',
334 'client_name' => ''
335 );
Barry Mienydd671972010-10-04 16:33:58 +0200336
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 foreach ($defaults as $key => $val)
338 {
339 if (isset($config[$key]))
340 {
341 $method = 'set_'.$key;
342 if (method_exists($this, $method))
343 {
344 $this->$method($config[$key]);
345 }
346 else
347 {
348 $this->$key = $config[$key];
Barry Mienydd671972010-10-04 16:33:58 +0200349 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
351 else
352 {
353 $this->$key = $val;
354 }
355 }
Barry Mienydd671972010-10-04 16:33:58 +0200356
Derek Jonese9d723f2010-07-12 10:10:59 -0500357 // if a file_name was provided in the config, use it instead of the user input
358 // supplied file name for all uploads until initialized again
359 $this->_file_name_override = $this->file_name;
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 }
Barry Mienydd671972010-10-04 16:33:58 +0200361
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200363
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 /**
365 * Perform the file upload
366 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200367 * @param string $field
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200369 */
Greg Aker58fdee82010-11-10 15:07:09 -0600370 public function do_upload($field = 'userfile')
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300372 // Is $_FILES[$field] set? If not, no reason to continue.
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 if ( ! isset($_FILES[$field]))
374 {
375 $this->set_error('upload_no_file_selected');
376 return FALSE;
377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 // Is the upload path valid?
380 if ( ! $this->validate_upload_path())
381 {
382 // errors will already be set by validate_upload_path() so just return FALSE
383 return FALSE;
384 }
385
386 // Was the file able to be uploaded? If not, determine the reason why.
387 if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))
388 {
389 $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error'];
390
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300391 switch ($error)
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
Darren Benneye123a602013-03-30 18:17:54 +0000393 case UPLOAD_ERR_INI_SIZE:
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 $this->set_error('upload_file_exceeds_limit');
395 break;
Darren Benneye123a602013-03-30 18:17:54 +0000396 case UPLOAD_ERR_FORM_SIZE:
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 $this->set_error('upload_file_exceeds_form_limit');
398 break;
Darren Benneye123a602013-03-30 18:17:54 +0000399 case UPLOAD_ERR_PARTIAL:
Barry Mienydd671972010-10-04 16:33:58 +0200400 $this->set_error('upload_file_partial');
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 break;
Darren Benneye123a602013-03-30 18:17:54 +0000402 case UPLOAD_ERR_NO_FILE:
Barry Mienydd671972010-10-04 16:33:58 +0200403 $this->set_error('upload_no_file_selected');
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 break;
Darren Benneye123a602013-03-30 18:17:54 +0000405 case UPLOAD_ERR_NO_TMP_DIR:
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 $this->set_error('upload_no_temp_directory');
407 break;
Darren Benneye123a602013-03-30 18:17:54 +0000408 case UPLOAD_ERR_CANT_WRITE:
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 $this->set_error('upload_unable_to_write_file');
410 break;
Darren Benneye123a602013-03-30 18:17:54 +0000411 case UPLOAD_ERR_EXTENSION:
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 $this->set_error('upload_stopped_by_extension');
413 break;
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300414 default:
415 $this->set_error('upload_no_file_selected');
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 break;
417 }
418
419 return FALSE;
420 }
421
422 // Set the uploaded data as class variables
Barry Mienydd671972010-10-04 16:33:58 +0200423 $this->file_temp = $_FILES[$field]['tmp_name'];
424 $this->file_size = $_FILES[$field]['size'];
Andrey Andreevd60e7002012-06-17 00:03:03 +0300425
426 // Skip MIME type detection?
427 if ($this->detect_mime !== FALSE)
428 {
429 $this->_file_mime_type($_FILES[$field]);
430 }
431
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300432 $this->file_type = preg_replace('/^(.+?);.*$/', '\\1', $this->file_type);
Derek Jones616fb022010-04-22 16:52:18 -0500433 $this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
Derek Jonese9d723f2010-07-12 10:10:59 -0500434 $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
435 $this->file_ext = $this->get_extension($this->file_name);
436 $this->client_name = $this->file_name;
Barry Mienydd671972010-10-04 16:33:58 +0200437
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 // Is the file type allowed to be uploaded?
439 if ( ! $this->is_allowed_filetype())
440 {
441 $this->set_error('upload_invalid_filetype');
442 return FALSE;
443 }
444
Derek Jonese9d723f2010-07-12 10:10:59 -0500445 // if we're overriding, let's now make sure the new name and type is allowed
Alex Bilbied261b1e2012-06-02 11:12:16 +0100446 if ($this->_file_name_override !== '')
Derek Jonese9d723f2010-07-12 10:10:59 -0500447 {
448 $this->file_name = $this->_prep_filename($this->_file_name_override);
Phil Sturgeon1e74da22010-12-15 10:45:06 +0000449
450 // If no extension was provided in the file_name config item, use the uploaded one
Pascal Kriete14287f32011-02-14 13:39:34 -0500451 if (strpos($this->_file_name_override, '.') === FALSE)
Phil Sturgeon1e74da22010-12-15 10:45:06 +0000452 {
453 $this->file_name .= $this->file_ext;
454 }
Phil Sturgeon1e74da22010-12-15 10:45:06 +0000455 else
456 {
vlakoff35672462013-02-15 01:36:04 +0100457 // An extension was provided, let's have it!
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300458 $this->file_ext = $this->get_extension($this->_file_name_override);
Phil Sturgeon1e74da22010-12-15 10:45:06 +0000459 }
Derek Jonese9d723f2010-07-12 10:10:59 -0500460
461 if ( ! $this->is_allowed_filetype(TRUE))
462 {
463 $this->set_error('upload_invalid_filetype');
Barry Mienydd671972010-10-04 16:33:58 +0200464 return FALSE;
Derek Jonese9d723f2010-07-12 10:10:59 -0500465 }
466 }
Barry Mienydd671972010-10-04 16:33:58 +0200467
Derek Jonese9d723f2010-07-12 10:10:59 -0500468 // Convert the file size to kilobytes
469 if ($this->file_size > 0)
470 {
471 $this->file_size = round($this->file_size/1024, 2);
472 }
473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 // Is the file size within the allowed maximum?
475 if ( ! $this->is_allowed_filesize())
476 {
477 $this->set_error('upload_invalid_filesize');
478 return FALSE;
479 }
480
481 // Are the image dimensions within the allowed size?
vlakoffc941d852013-08-06 14:44:40 +0200482 // Note: This can fail if the server has an open_basedir restriction.
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 if ( ! $this->is_allowed_dimensions())
484 {
485 $this->set_error('upload_invalid_dimensions');
486 return FALSE;
487 }
488
489 // Sanitize the file name for security
Andrey Andreev119d8a72014-01-08 15:27:53 +0200490 $this->file_name = $this->CI->security->sanitize_filename($this->file_name);
Barry Mienydd671972010-10-04 16:33:58 +0200491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 // Truncate the file name if it's too long
493 if ($this->max_filename > 0)
494 {
495 $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
496 }
497
498 // Remove white spaces in the name
Alex Bilbied261b1e2012-06-02 11:12:16 +0100499 if ($this->remove_spaces === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300501 $this->file_name = preg_replace('/\s+/', '_', $this->file_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 }
503
504 /*
505 * Validate the file name
506 * This function appends an number onto the end of
507 * the file if one with the same name already exists.
508 * If it returns false there was a problem.
509 */
510 $this->orig_name = $this->file_name;
511
Alex Bilbied261b1e2012-06-02 11:12:16 +0100512 if ($this->overwrite === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 {
514 $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
Barry Mienydd671972010-10-04 16:33:58 +0200515
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 if ($this->file_name === FALSE)
517 {
518 return FALSE;
519 }
520 }
521
522 /*
Derek Jonese9d723f2010-07-12 10:10:59 -0500523 * Run the file through the XSS hacking filter
524 * This helps prevent malicious code from being
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300525 * embedded within a file. Scripts can easily
Derek Jonese9d723f2010-07-12 10:10:59 -0500526 * be disguised as images or other file types.
527 */
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300528 if ($this->xss_clean && $this->do_xss_clean() === FALSE)
Derek Jonese9d723f2010-07-12 10:10:59 -0500529 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300530 $this->set_error('upload_unable_to_write_file');
531 return FALSE;
Derek Jonese9d723f2010-07-12 10:10:59 -0500532 }
533
534 /*
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 * Move the file to the final destination
536 * To deal with different server configurations
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300537 * we'll attempt to use copy() first. If that fails
538 * we'll use move_uploaded_file(). One of the two should
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 * reliably work in most environments
540 */
541 if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name))
542 {
543 if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
544 {
Barry Mienydd671972010-10-04 16:33:58 +0200545 $this->set_error('upload_destination_error');
546 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 }
548 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000549
550 /*
551 * Set the finalized image dimensions
552 * This sets the image width/height (assuming the
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300553 * file was an image). We use this information
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 * in the "data" function.
555 */
556 $this->set_image_properties($this->upload_path.$this->file_name);
557
558 return TRUE;
559 }
Barry Mienydd671972010-10-04 16:33:58 +0200560
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 /**
564 * Finalized Data Array
Barry Mienydd671972010-10-04 16:33:58 +0200565 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 * Returns an associative array containing all of the information
567 * related to the upload, allowing the developer easy access in one array.
568 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200569 * @param string $index
Michiel Vugteveen0ee287e2012-06-11 10:38:14 +0200570 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200571 */
Michiel Vugteveendca9f232012-06-11 09:17:14 +0200572 public function data($index = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 {
Michiel Vugteveendca9f232012-06-11 09:17:14 +0200574 $data = array(
Michiel Vugteveen3a7fb042012-06-11 09:29:16 +0200575 'file_name' => $this->file_name,
576 'file_type' => $this->file_type,
577 'file_path' => $this->upload_path,
578 'full_path' => $this->upload_path.$this->file_name,
579 'raw_name' => str_replace($this->file_ext, '', $this->file_name),
580 'orig_name' => $this->orig_name,
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300581 'client_name' => $this->client_name,
Michiel Vugteveen3a7fb042012-06-11 09:29:16 +0200582 'file_ext' => $this->file_ext,
583 'file_size' => $this->file_size,
584 'is_image' => $this->is_image(),
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300585 'image_width' => $this->image_width,
586 'image_height' => $this->image_height,
587 'image_type' => $this->image_type,
588 'image_size_str' => $this->image_size_str,
589 );
Michiel Vugteveendca9f232012-06-11 09:17:14 +0200590
Michiel Vugteveen46a04292012-06-11 10:37:52 +0200591 if ( ! empty($index))
Michiel Vugteveendca9f232012-06-11 09:17:14 +0200592 {
Michiel Vugteveen46a04292012-06-11 10:37:52 +0200593 return isset($data[$index]) ? $data[$index] : NULL;
Michiel Vugteveendca9f232012-06-11 09:17:14 +0200594 }
595
Michiel Vugteveen46a04292012-06-11 10:37:52 +0200596 return $data;
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 }
Barry Mienydd671972010-10-04 16:33:58 +0200598
Derek Allard2067d1a2008-11-13 22:59:24 +0000599 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200600
Derek Allard2067d1a2008-11-13 22:59:24 +0000601 /**
602 * Set Upload Path
603 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200604 * @param string $path
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200606 */
Greg Aker58fdee82010-11-10 15:07:09 -0600607 public function set_upload_path($path)
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 {
609 // Make sure it has a trailing slash
610 $this->upload_path = rtrim($path, '/').'/';
611 }
Barry Mienydd671972010-10-04 16:33:58 +0200612
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200614
Derek Allard2067d1a2008-11-13 22:59:24 +0000615 /**
616 * Set the file name
617 *
618 * This function takes a filename/path as input and looks for the
619 * existence of a file with the same name. If found, it will append a
620 * number to the end of the filename to avoid overwriting a pre-existing file.
621 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200622 * @param string $path
623 * @param string $filename
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200625 */
Greg Aker58fdee82010-11-10 15:07:09 -0600626 public function set_filename($path, $filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100628 if ($this->encrypt_name === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200629 {
Barry Mienydd671972010-10-04 16:33:58 +0200630 $filename = md5(uniqid(mt_rand())).$this->file_ext;
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 }
Barry Mienydd671972010-10-04 16:33:58 +0200632
Derek Allard2067d1a2008-11-13 22:59:24 +0000633 if ( ! file_exists($path.$filename))
634 {
635 return $filename;
636 }
Barry Mienydd671972010-10-04 16:33:58 +0200637
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 $filename = str_replace($this->file_ext, '', $filename);
Barry Mienydd671972010-10-04 16:33:58 +0200639
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 $new_filename = '';
Adam Jackettccbbea12011-08-21 16:19:11 -0400641 for ($i = 1; $i < $this->max_filename_increment; $i++)
Barry Mienydd671972010-10-04 16:33:58 +0200642 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 if ( ! file_exists($path.$filename.$i.$this->file_ext))
644 {
645 $new_filename = $filename.$i.$this->file_ext;
646 break;
647 }
648 }
649
Alex Bilbied261b1e2012-06-02 11:12:16 +0100650 if ($new_filename === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 {
652 $this->set_error('upload_bad_filename');
653 return FALSE;
654 }
655 else
656 {
657 return $new_filename;
658 }
659 }
Barry Mienydd671972010-10-04 16:33:58 +0200660
Derek Allard2067d1a2008-11-13 22:59:24 +0000661 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200662
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 /**
664 * Set Maximum File Size
665 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200666 * @param int $n
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200668 */
Greg Aker58fdee82010-11-10 15:07:09 -0600669 public function set_max_filesize($n)
Derek Allard2067d1a2008-11-13 22:59:24 +0000670 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300671 $this->max_size = ((int) $n < 0) ? 0 : (int) $n;
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 }
Barry Mienydd671972010-10-04 16:33:58 +0200673
Derek Allard2067d1a2008-11-13 22:59:24 +0000674 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200675
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 /**
677 * Set Maximum File Name Length
678 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200679 * @param int $n
Derek Allard2067d1a2008-11-13 22:59:24 +0000680 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200681 */
Greg Aker58fdee82010-11-10 15:07:09 -0600682 public function set_max_filename($n)
Derek Allard2067d1a2008-11-13 22:59:24 +0000683 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300684 $this->max_filename = ((int) $n < 0) ? 0 : (int) $n;
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 }
686
687 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200688
Derek Allard2067d1a2008-11-13 22:59:24 +0000689 /**
690 * Set Maximum Image Width
691 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200692 * @param int $n
Derek Allard2067d1a2008-11-13 22:59:24 +0000693 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200694 */
Greg Aker58fdee82010-11-10 15:07:09 -0600695 public function set_max_width($n)
Derek Allard2067d1a2008-11-13 22:59:24 +0000696 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300697 $this->max_width = ((int) $n < 0) ? 0 : (int) $n;
Derek Allard2067d1a2008-11-13 22:59:24 +0000698 }
Barry Mienydd671972010-10-04 16:33:58 +0200699
Derek Allard2067d1a2008-11-13 22:59:24 +0000700 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200701
Derek Allard2067d1a2008-11-13 22:59:24 +0000702 /**
703 * Set Maximum Image Height
704 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200705 * @param int $n
Derek Allard2067d1a2008-11-13 22:59:24 +0000706 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200707 */
Greg Aker58fdee82010-11-10 15:07:09 -0600708 public function set_max_height($n)
Derek Allard2067d1a2008-11-13 22:59:24 +0000709 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300710 $this->max_height = ((int) $n < 0) ? 0 : (int) $n;
Derek Allard2067d1a2008-11-13 22:59:24 +0000711 }
Barry Mienydd671972010-10-04 16:33:58 +0200712
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200714
Derek Allard2067d1a2008-11-13 22:59:24 +0000715 /**
Andrey Andreev05aa2d62012-12-03 16:06:55 +0200716 * Set minimum image width
717 *
718 * @param int $n
719 * @return void
720 */
721 public function set_min_width($n)
722 {
723 $this->min_width = ((int) $n < 0) ? 0 : (int) $n;
724 }
725
726 // --------------------------------------------------------------------
727
728 /**
729 * Set minimum image height
730 *
731 * @param int $n
732 * @return void
733 */
734 public function set_min_height($n)
735 {
736 $this->min_height = ((int) $n < 0) ? 0 : (int) $n;
737 }
738
739 // --------------------------------------------------------------------
740
741 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000742 * Set Allowed File Types
743 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200744 * @param string $types
Derek Allard2067d1a2008-11-13 22:59:24 +0000745 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200746 */
Greg Aker58fdee82010-11-10 15:07:09 -0600747 public function set_allowed_types($types)
Derek Allard2067d1a2008-11-13 22:59:24 +0000748 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300749 if ( ! is_array($types) && $types === '*')
Derek Jonese12f64e2010-03-02 22:55:08 -0600750 {
751 $this->allowed_types = '*';
752 return;
753 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000754 $this->allowed_types = explode('|', $types);
755 }
Barry Mienydd671972010-10-04 16:33:58 +0200756
Derek Allard2067d1a2008-11-13 22:59:24 +0000757 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200758
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 /**
760 * Set Image Properties
761 *
762 * Uses GD to determine the width/height/type of image
763 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200764 * @param string $path
Derek Allard2067d1a2008-11-13 22:59:24 +0000765 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200766 */
Greg Aker58fdee82010-11-10 15:07:09 -0600767 public function set_image_properties($path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000768 {
769 if ( ! $this->is_image())
770 {
771 return;
772 }
773
774 if (function_exists('getimagesize'))
775 {
776 if (FALSE !== ($D = @getimagesize($path)))
Barry Mienydd671972010-10-04 16:33:58 +0200777 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000778 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
779
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300780 $this->image_width = $D[0];
781 $this->image_height = $D[1];
782 $this->image_type = isset($types[$D[2]]) ? $types[$D[2]] : 'unknown';
783 $this->image_size_str = $D[3]; // string containing height and width
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 }
785 }
786 }
Barry Mienydd671972010-10-04 16:33:58 +0200787
Derek Allard2067d1a2008-11-13 22:59:24 +0000788 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200789
Derek Allard2067d1a2008-11-13 22:59:24 +0000790 /**
791 * Set XSS Clean
792 *
793 * Enables the XSS flag so that the file that was uploaded
794 * will be run through the XSS filter.
795 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200796 * @param bool $flag
Derek Allard2067d1a2008-11-13 22:59:24 +0000797 * @return void
798 */
Greg Aker58fdee82010-11-10 15:07:09 -0600799 public function set_xss_clean($flag = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000800 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100801 $this->xss_clean = ($flag === TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000802 }
Barry Mienydd671972010-10-04 16:33:58 +0200803
Derek Allard2067d1a2008-11-13 22:59:24 +0000804 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200805
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 /**
807 * Validate the image
808 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000809 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200810 */
Greg Aker58fdee82010-11-10 15:07:09 -0600811 public function is_image()
Derek Allard2067d1a2008-11-13 22:59:24 +0000812 {
813 // IE will sometimes return odd mime-types during upload, so here we just standardize all
814 // jpegs or pngs to the same file type.
815
Derek Jones4b9c6292011-07-01 17:40:48 -0500816 $png_mimes = array('image/x-png');
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg');
Barry Mienydd671972010-10-04 16:33:58 +0200818
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 if (in_array($this->file_type, $png_mimes))
820 {
821 $this->file_type = 'image/png';
822 }
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300823 elseif (in_array($this->file_type, $jpeg_mimes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000824 {
825 $this->file_type = 'image/jpeg';
826 }
827
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300828 $img_mimes = array('image/gif', 'image/jpeg', 'image/png');
Derek Allard2067d1a2008-11-13 22:59:24 +0000829
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300830 return in_array($this->file_type, $img_mimes, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000831 }
Barry Mienydd671972010-10-04 16:33:58 +0200832
Derek Allard2067d1a2008-11-13 22:59:24 +0000833 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200834
Derek Allard2067d1a2008-11-13 22:59:24 +0000835 /**
836 * Verify that the filetype is allowed
837 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200838 * @param bool $ignore_mime
Derek Allard2067d1a2008-11-13 22:59:24 +0000839 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200840 */
Greg Aker58fdee82010-11-10 15:07:09 -0600841 public function is_allowed_filetype($ignore_mime = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000842 {
Andrey Andreev6ca407e2012-03-01 15:33:21 +0200843 if ($this->allowed_types === '*')
Derek Jonese12f64e2010-03-02 22:55:08 -0600844 {
845 return TRUE;
846 }
Barry Mienydd671972010-10-04 16:33:58 +0200847
Andrey Andreev6ca407e2012-03-01 15:33:21 +0200848 if ( ! is_array($this->allowed_types) OR count($this->allowed_types) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000849 {
850 $this->set_error('upload_no_file_types');
851 return FALSE;
852 }
Barry Mienydd671972010-10-04 16:33:58 +0200853
Derek Jonese9d723f2010-07-12 10:10:59 -0500854 $ext = strtolower(ltrim($this->file_ext, '.'));
Barry Mienydd671972010-10-04 16:33:58 +0200855
Derek Jonese9d723f2010-07-12 10:10:59 -0500856 if ( ! in_array($ext, $this->allowed_types))
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 {
Derek Jonese9d723f2010-07-12 10:10:59 -0500858 return FALSE;
859 }
Derek Jonesafa282f2009-02-10 17:11:52 +0000860
Barry Mienydd671972010-10-04 16:33:58 +0200861 // Images get some additional checks
Derek Jonese9d723f2010-07-12 10:10:59 -0500862 $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
Barry Mienydd671972010-10-04 16:33:58 +0200863
Andrey Andreev6ca407e2012-03-01 15:33:21 +0200864 if (in_array($ext, $image_types) && @getimagesize($this->file_temp) === FALSE)
Derek Jonese9d723f2010-07-12 10:10:59 -0500865 {
Andrey Andreev6ca407e2012-03-01 15:33:21 +0200866 return FALSE;
Derek Jonese9d723f2010-07-12 10:10:59 -0500867 }
Barry Mienydd671972010-10-04 16:33:58 +0200868
Derek Jonese9d723f2010-07-12 10:10:59 -0500869 if ($ignore_mime === TRUE)
870 {
871 return TRUE;
872 }
Barry Mienydd671972010-10-04 16:33:58 +0200873
Derek Jonese9d723f2010-07-12 10:10:59 -0500874 $mime = $this->mimes_types($ext);
Barry Mienydd671972010-10-04 16:33:58 +0200875
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300876 if (is_array($mime) && in_array($this->file_type, $mime, TRUE))
Derek Jonese9d723f2010-07-12 10:10:59 -0500877 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300878 return TRUE;
Derek Jonese9d723f2010-07-12 10:10:59 -0500879 }
Andrey Andreev6ca407e2012-03-01 15:33:21 +0200880 elseif ($mime === $this->file_type)
Derek Jonese9d723f2010-07-12 10:10:59 -0500881 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300882 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 }
Barry Mienydd671972010-10-04 16:33:58 +0200884
Derek Allard2067d1a2008-11-13 22:59:24 +0000885 return FALSE;
886 }
Barry Mienydd671972010-10-04 16:33:58 +0200887
Derek Allard2067d1a2008-11-13 22:59:24 +0000888 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200889
Derek Allard2067d1a2008-11-13 22:59:24 +0000890 /**
891 * Verify that the file is within the allowed size
892 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000893 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200894 */
Greg Aker58fdee82010-11-10 15:07:09 -0600895 public function is_allowed_filesize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000896 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100897 return ($this->max_size === 0 OR $this->max_size > $this->file_size);
Derek Allard2067d1a2008-11-13 22:59:24 +0000898 }
Barry Mienydd671972010-10-04 16:33:58 +0200899
Derek Allard2067d1a2008-11-13 22:59:24 +0000900 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200901
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 /**
903 * Verify that the image is within the allowed width/height
904 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000905 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200906 */
Greg Aker58fdee82010-11-10 15:07:09 -0600907 public function is_allowed_dimensions()
Derek Allard2067d1a2008-11-13 22:59:24 +0000908 {
909 if ( ! $this->is_image())
910 {
911 return TRUE;
912 }
913
914 if (function_exists('getimagesize'))
915 {
916 $D = @getimagesize($this->file_temp);
917
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300918 if ($this->max_width > 0 && $D[0] > $this->max_width)
Derek Allard2067d1a2008-11-13 22:59:24 +0000919 {
920 return FALSE;
921 }
922
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300923 if ($this->max_height > 0 && $D[1] > $this->max_height)
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 {
925 return FALSE;
926 }
Andrey Andreev05aa2d62012-12-03 16:06:55 +0200927
928 if ($this->min_width > 0 && $D[0] < $this->min_width)
929 {
930 return FALSE;
931 }
932
933 if ($this->min_height > 0 && $D[1] < $this->min_height)
934 {
935 return FALSE;
936 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 }
938
939 return TRUE;
940 }
Barry Mienydd671972010-10-04 16:33:58 +0200941
Derek Allard2067d1a2008-11-13 22:59:24 +0000942 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200943
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 /**
945 * Validate Upload Path
946 *
947 * Verifies that it is a valid upload path with proper permissions.
948 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200950 */
Greg Aker58fdee82010-11-10 15:07:09 -0600951 public function validate_upload_path()
Derek Allard2067d1a2008-11-13 22:59:24 +0000952 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100953 if ($this->upload_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 {
955 $this->set_error('upload_no_filepath');
956 return FALSE;
957 }
Barry Mienydd671972010-10-04 16:33:58 +0200958
Andrey Andreevc839d282012-06-07 14:35:27 +0300959 if (@realpath($this->upload_path) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000960 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300961 $this->upload_path = str_replace('\\', '/', realpath($this->upload_path));
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 }
963
964 if ( ! @is_dir($this->upload_path))
965 {
966 $this->set_error('upload_no_filepath');
967 return FALSE;
968 }
969
970 if ( ! is_really_writable($this->upload_path))
971 {
972 $this->set_error('upload_not_writable');
973 return FALSE;
974 }
975
Andrey Andreev8e6f7a92012-03-26 20:13:00 +0300976 $this->upload_path = preg_replace('/(.+?)\/*$/', '\\1/', $this->upload_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 return TRUE;
978 }
Barry Mienydd671972010-10-04 16:33:58 +0200979
Derek Allard2067d1a2008-11-13 22:59:24 +0000980 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200981
Derek Allard2067d1a2008-11-13 22:59:24 +0000982 /**
983 * Extract the file extension
984 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +0200985 * @param string $filename
Derek Allard2067d1a2008-11-13 22:59:24 +0000986 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200987 */
Greg Aker58fdee82010-11-10 15:07:09 -0600988 public function get_extension($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000989 {
990 $x = explode('.', $filename);
Adrianf496d132013-06-24 15:56:45 +0200991
Adrian74a228b2013-06-25 12:09:22 +0200992 if (count($x) === 1)
993 {
994 return '';
995 }
996
997 $ext = ($this->file_ext_tolower) ? strtolower(end($x)) : end($x);
998 return '.'.$ext;
Barry Mienydd671972010-10-04 16:33:58 +0200999 }
1000
Derek Allard2067d1a2008-11-13 22:59:24 +00001001 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001002
Derek Allard2067d1a2008-11-13 22:59:24 +00001003 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001004 * Limit the File Name Length
1005 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001006 * @param string $filename
1007 * @param int $length
Derek Allard2067d1a2008-11-13 22:59:24 +00001008 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001009 */
Greg Aker58fdee82010-11-10 15:07:09 -06001010 public function limit_filename_length($filename, $length)
Derek Allard2067d1a2008-11-13 22:59:24 +00001011 {
1012 if (strlen($filename) < $length)
1013 {
1014 return $filename;
1015 }
Barry Mienydd671972010-10-04 16:33:58 +02001016
Derek Allard2067d1a2008-11-13 22:59:24 +00001017 $ext = '';
1018 if (strpos($filename, '.') !== FALSE)
1019 {
1020 $parts = explode('.', $filename);
1021 $ext = '.'.array_pop($parts);
1022 $filename = implode('.', $parts);
1023 }
Barry Mienydd671972010-10-04 16:33:58 +02001024
Derek Allard2067d1a2008-11-13 22:59:24 +00001025 return substr($filename, 0, ($length - strlen($ext))).$ext;
1026 }
1027
1028 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001029
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 /**
1031 * Runs the file through the XSS clean function
1032 *
1033 * This prevents people from embedding malicious code in their files.
1034 * I'm not sure that it won't negatively affect certain files in unexpected ways,
1035 * but so far I haven't found that it causes trouble.
1036 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001037 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001038 */
Greg Aker58fdee82010-11-10 15:07:09 -06001039 public function do_xss_clean()
Barry Mienydd671972010-10-04 16:33:58 +02001040 {
Derek Jonese9d723f2010-07-12 10:10:59 -05001041 $file = $this->file_temp;
Barry Mienydd671972010-10-04 16:33:58 +02001042
Andrey Andreev5036c9c2012-06-04 15:34:56 +03001043 if (filesize($file) == 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001044 {
1045 return FALSE;
1046 }
Barry Mienydd671972010-10-04 16:33:58 +02001047
Andrey Andreevc839d282012-06-07 14:35:27 +03001048 if (memory_get_usage() && ($memory_limit = ini_get('memory_limit')))
Greg Akerf82e51c2010-04-14 19:33:50 -05001049 {
Andrey Andreevc839d282012-06-07 14:35:27 +03001050 $memory_limit *= 1024 * 1024;
Barry Mienydd671972010-10-04 16:33:58 +02001051
Greg Akerc78a2592010-06-09 11:45:32 -05001052 // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001053 // into scientific notation. number_format() ensures this number is an integer
Greg Akerc78a2592010-06-09 11:45:32 -05001054 // http://bugs.php.net/bug.php?id=43053
Barry Mienydd671972010-10-04 16:33:58 +02001055
Andrey Andreevc839d282012-06-07 14:35:27 +03001056 $memory_limit = number_format(ceil(filesize($file) + $memory_limit), 0, '.', '');
Barry Mienydd671972010-10-04 16:33:58 +02001057
Andrey Andreevc839d282012-06-07 14:35:27 +03001058 ini_set('memory_limit', $memory_limit); // When an integer is used, the value is measured in bytes. - PHP.net
Greg Akerf82e51c2010-04-14 19:33:50 -05001059 }
1060
1061 // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but
1062 // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001063 // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this
1064 // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of
Barry Mienydd671972010-10-04 16:33:58 +02001065 // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an
Greg Akerf82e51c2010-04-14 19:33:50 -05001066 // attempted XSS attack.
1067
1068 if (function_exists('getimagesize') && @getimagesize($file) !== FALSE)
1069 {
Barry Mienydd671972010-10-04 16:33:58 +02001070 if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary
1071 {
Greg Akerf82e51c2010-04-14 19:33:50 -05001072 return FALSE; // Couldn't open the file, return FALSE
Barry Mienydd671972010-10-04 16:33:58 +02001073 }
Greg Akerf82e51c2010-04-14 19:33:50 -05001074
Barry Mienydd671972010-10-04 16:33:58 +02001075 $opening_bytes = fread($file, 256);
1076 fclose($file);
Greg Akerf82e51c2010-04-14 19:33:50 -05001077
1078 // These are known to throw IE into mime-type detection chaos
1079 // <a, <body, <head, <html, <img, <plaintext, <pre, <script, <table, <title
1080 // title is basically just in SVG, but we filter it anyhow
1081
vlakoff35672462013-02-15 01:36:04 +01001082 // if it's an image or no "triggers" detected in the first 256 bytes - we're good
Andrey Andreevc839d282012-06-07 14:35:27 +03001083 return ! preg_match('/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i', $opening_bytes);
Greg Akerf82e51c2010-04-14 19:33:50 -05001084 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001085
1086 if (($data = @file_get_contents($file)) === FALSE)
1087 {
1088 return FALSE;
1089 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001090
Andrey Andreev119d8a72014-01-08 15:27:53 +02001091 return $this->CI->security->xss_clean($data, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001092 }
Barry Mienydd671972010-10-04 16:33:58 +02001093
Derek Allard2067d1a2008-11-13 22:59:24 +00001094 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001095
Derek Allard2067d1a2008-11-13 22:59:24 +00001096 /**
1097 * Set an error message
1098 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001099 * @param string $msg
Derek Allard2067d1a2008-11-13 22:59:24 +00001100 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001101 */
Greg Aker58fdee82010-11-10 15:07:09 -06001102 public function set_error($msg)
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 {
Andrey Andreev119d8a72014-01-08 15:27:53 +02001104 $this->CI->lang->load('upload');
Barry Mienydd671972010-10-04 16:33:58 +02001105
Andrey Andreev119d8a72014-01-08 15:27:53 +02001106 is_array($msg) OR $msg = array($msg);
Darren Benney4a8d1902013-03-30 20:07:49 +00001107
Darren Benney38d5f4b2013-03-30 21:00:38 +00001108 foreach ($msg as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 {
Andrey Andreev119d8a72014-01-08 15:27:53 +02001110 $msg = ($this->CI->lang->line($val) === FALSE) ? $val : $this->CI->lang->line($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001111 $this->error_msg[] = $msg;
1112 log_message('error', $msg);
1113 }
1114 }
Barry Mienydd671972010-10-04 16:33:58 +02001115
Derek Allard2067d1a2008-11-13 22:59:24 +00001116 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001117
Derek Allard2067d1a2008-11-13 22:59:24 +00001118 /**
1119 * Display the error message
1120 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001121 * @param string $open
1122 * @param string $close
Derek Allard2067d1a2008-11-13 22:59:24 +00001123 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001124 */
Greg Aker58fdee82010-11-10 15:07:09 -06001125 public function display_errors($open = '<p>', $close = '</p>')
Derek Allard2067d1a2008-11-13 22:59:24 +00001126 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001127 return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001128 }
Barry Mienydd671972010-10-04 16:33:58 +02001129
Derek Allard2067d1a2008-11-13 22:59:24 +00001130 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001131
Derek Allard2067d1a2008-11-13 22:59:24 +00001132 /**
1133 * List of Mime Types
1134 *
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001135 * This is a list of mime types. We use it to validate
Derek Allard2067d1a2008-11-13 22:59:24 +00001136 * the "allowed types" set by the developer
1137 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001138 * @param string $mime
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001140 */
Greg Aker58fdee82010-11-10 15:07:09 -06001141 public function mimes_types($mime)
Derek Allard2067d1a2008-11-13 22:59:24 +00001142 {
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001143 return isset($this->mimes[$mime]) ? $this->mimes[$mime] : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001144 }
1145
1146 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001147
Derek Allard2067d1a2008-11-13 22:59:24 +00001148 /**
1149 * Prep Filename
1150 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001151 * Prevents possible script execution from Apache's handling
1152 * of files' multiple extensions.
Derek Allard2067d1a2008-11-13 22:59:24 +00001153 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001154 * @link http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
1155 *
1156 * @param string $filename
Derek Allard2067d1a2008-11-13 22:59:24 +00001157 * @return string
1158 */
Greg Aker58fdee82010-11-10 15:07:09 -06001159 protected function _prep_filename($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +00001160 {
Andrey Andreev32c72122013-10-21 15:35:05 +03001161 if ($this->mod_mime_fix === FALSE OR $this->allowed_types === '*' OR strpos($filename, '.') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 {
1163 return $filename;
1164 }
Derek Allard616dab82009-02-16 15:44:32 +00001165
Derek Allard2067d1a2008-11-13 22:59:24 +00001166 $parts = explode('.', $filename);
1167 $ext = array_pop($parts);
1168 $filename = array_shift($parts);
Derek Allard616dab82009-02-16 15:44:32 +00001169
Derek Allard2067d1a2008-11-13 22:59:24 +00001170 foreach ($parts as $part)
1171 {
Derek Jonese9d723f2010-07-12 10:10:59 -05001172 if ( ! in_array(strtolower($part), $this->allowed_types) OR $this->mimes_types(strtolower($part)) === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001173 {
1174 $filename .= '.'.$part.'_';
1175 }
1176 else
1177 {
1178 $filename .= '.'.$part;
1179 }
1180 }
Derek Allardd70b0642009-02-16 13:51:42 +00001181
Andrey Andreev8e6f7a92012-03-26 20:13:00 +03001182 return $filename.'.'.$ext;
Derek Allard2067d1a2008-11-13 22:59:24 +00001183 }
1184
1185 // --------------------------------------------------------------------
1186
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001187 /**
1188 * File MIME type
1189 *
1190 * Detects the (actual) MIME type of the uploaded file, if possible.
1191 * The input array is expected to be $_FILES[$field]
1192 *
Andrey Andreevf5ccd122012-11-02 00:17:39 +02001193 * @param array $file
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001194 * @return void
1195 */
1196 protected function _file_mime_type($file)
1197 {
Andrey Andreeva49e3812011-12-09 13:05:22 +02001198 // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
Andrey Andreevf7aed122011-12-13 11:01:06 +02001199 $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
Andrey Andreeva49e3812011-12-09 13:05:22 +02001200
1201 /* Fileinfo extension - most reliable method
1202 *
1203 * Unfortunately, prior to PHP 5.3 - it's only available as a PECL extension and the
1204 * more convenient FILEINFO_MIME_TYPE flag doesn't exist.
1205 */
1206 if (function_exists('finfo_file'))
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001207 {
Andrey Andreevd60e7002012-06-17 00:03:03 +03001208 $finfo = @finfo_open(FILEINFO_MIME);
Andrey Andreeva49e3812011-12-09 13:05:22 +02001209 if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001210 {
Andrey Andreeva49e3812011-12-09 13:05:22 +02001211 $mime = @finfo_file($finfo, $file['tmp_name']);
1212 finfo_close($finfo);
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001213
1214 /* According to the comments section of the PHP manual page,
1215 * it is possible that this function returns an empty string
Andrey Andreev2cec39f2011-09-24 22:59:37 +03001216 * for some files (e.g. if they don't exist in the magic MIME database)
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001217 */
Andrey Andreeva49e3812011-12-09 13:05:22 +02001218 if (is_string($mime) && preg_match($regexp, $mime, $matches))
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001219 {
Andrey Andreeva49e3812011-12-09 13:05:22 +02001220 $this->file_type = $matches[1];
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001221 return;
1222 }
1223 }
1224 }
1225
Andrey Andreeva49e3812011-12-09 13:05:22 +02001226 /* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
1227 * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
1228 * was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
1229 * than mime_content_type() as well, hence the attempts to try calling the command line with
1230 * three different functions.
Andrey Andreev6700b932011-09-24 14:25:33 +03001231 *
1232 * Notes:
Andrey Andreev59654312011-12-02 14:28:54 +02001233 * - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
Andrey Andreeva49e3812011-12-09 13:05:22 +02001234 * - many system admins would disable the exec(), shell_exec(), popen() and similar functions
vlakofff3994252013-02-19 01:45:23 +01001235 * due to security concerns, hence the function_usable() checks
Andrey Andreev6700b932011-09-24 14:25:33 +03001236 */
Andrey Andreeva49e3812011-12-09 13:05:22 +02001237 if (DIRECTORY_SEPARATOR !== '\\')
Andrey Andreev6700b932011-09-24 14:25:33 +03001238 {
Andrey Andreevd60e7002012-06-17 00:03:03 +03001239 $cmd = function_exists('escapeshellarg')
1240 ? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
1241 : 'file --brief --mime '.$file['tmp_name'].' 2>&1';
Andrey Andreeva49e3812011-12-09 13:05:22 +02001242
Andrey Andreeve9d2dc82012-11-07 14:23:29 +02001243 if (function_usable('exec'))
Andrey Andreev6700b932011-09-24 14:25:33 +03001244 {
Andrey Andreeva49e3812011-12-09 13:05:22 +02001245 /* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
vlakofff3994252013-02-19 01:45:23 +01001246 * However, we only need the last line, which is the actual return value of exec(), and as such - it overwrites
Andrey Andreeva49e3812011-12-09 13:05:22 +02001247 * anything that could already be set for $mime previously. This effectively makes the second parameter a dummy
1248 * value, which is only put to allow us to get the return status code.
1249 */
1250 $mime = @exec($cmd, $mime, $return_status);
1251 if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches))
1252 {
1253 $this->file_type = $matches[1];
1254 return;
1255 }
1256 }
1257
Andrey Andreev5932a732013-09-13 14:45:53 +03001258 if ((bool) @ini_get('safe_mode') === FALSE && function_usable('shell_exec'))
Andrey Andreeva49e3812011-12-09 13:05:22 +02001259 {
1260 $mime = @shell_exec($cmd);
1261 if (strlen($mime) > 0)
1262 {
1263 $mime = explode("\n", trim($mime));
1264 if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
1265 {
1266 $this->file_type = $matches[1];
1267 return;
1268 }
1269 }
1270 }
1271
Andrey Andreeve9d2dc82012-11-07 14:23:29 +02001272 if (function_usable('popen'))
Andrey Andreeva49e3812011-12-09 13:05:22 +02001273 {
1274 $proc = @popen($cmd, 'r');
1275 if (is_resource($proc))
1276 {
tubalmartin010f1f42012-03-03 22:24:31 +01001277 $mime = @fread($proc, 512);
Andrey Andreeva49e3812011-12-09 13:05:22 +02001278 @pclose($proc);
1279 if ($mime !== FALSE)
1280 {
1281 $mime = explode("\n", trim($mime));
1282 if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
1283 {
1284 $this->file_type = $matches[1];
1285 return;
1286 }
1287 }
1288 }
1289 }
1290 }
1291
1292 // Fall back to the deprecated mime_content_type(), if available (still better than $_FILES[$field]['type'])
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001293 if (function_exists('mime_content_type'))
1294 {
1295 $this->file_type = @mime_content_type($file['tmp_name']);
Andrey Andreeva49e3812011-12-09 13:05:22 +02001296 if (strlen($this->file_type) > 0) // It's possible that mime_content_type() returns FALSE or an empty string
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001297 {
Andrey Andreev3a3c9472011-09-24 14:25:33 +03001298 return;
1299 }
1300 }
1301
1302 $this->file_type = $file['type'];
1303 }
1304
Derek Allard2067d1a2008-11-13 22:59:24 +00001305}
Derek Allard2067d1a2008-11-13 22:59:24 +00001306
1307/* End of file Upload.php */
Adrian74a228b2013-06-25 12:09:22 +02001308/* Location: ./system/libraries/Upload.php */