phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / includes / functions_upload.php

History | View | Annotate | Download (24.4 kB)

1 5110 acydburn
<?php
2 8146 acydburn
/**
3 5114 acydburn
*
4 5114 acydburn
* @package phpBB3
5 8146 acydburn
* @version $Id$
6 8146 acydburn
* @copyright (c) 2005 phpBB Group
7 8146 acydburn
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 5114 acydburn
*
9 5114 acydburn
*/
10 5110 acydburn
11 5114 acydburn
/**
12 8146 acydburn
* @ignore
13 8146 acydburn
*/
14 8146 acydburn
if (!defined('IN_PHPBB'))
15 8146 acydburn
{
16 8146 acydburn
        exit;
17 8146 acydburn
}
18 8146 acydburn
19 8146 acydburn
/**
20 6650 acydburn
* Responsible for holding all file relevant information, as well as doing file-specific operations.
21 5114 acydburn
* The {@link fileupload fileupload class} can be used to upload several files, each of them being this object to operate further on.
22 6058 acydburn
* @package phpBB3
23 5114 acydburn
*/
24 5110 acydburn
class filespec
25 5110 acydburn
{
26 5110 acydburn
        var $filename = '';
27 5110 acydburn
        var $realname = '';
28 5110 acydburn
        var $uploadname = '';
29 5110 acydburn
        var $mimetype = '';
30 5110 acydburn
        var $extension = '';
31 5110 acydburn
        var $filesize = 0;
32 5110 acydburn
        var $width = 0;
33 5110 acydburn
        var $height = 0;
34 6058 acydburn
        var $image_info = array();
35 5110 acydburn
36 5110 acydburn
        var $destination_file = '';
37 5110 acydburn
        var $destination_path = '';
38 5110 acydburn
39 5110 acydburn
        var $file_moved = false;
40 5110 acydburn
        var $init_error = false;
41 5110 acydburn
        var $local = false;
42 5110 acydburn
43 5110 acydburn
        var $error = array();
44 5110 acydburn
45 5110 acydburn
        var $upload = '';
46 5110 acydburn
47 5110 acydburn
        /**
48 5110 acydburn
        * File Class
49 6312 acydburn
        * @access private
50 5110 acydburn
        */
51 5110 acydburn
        function filespec($upload_ary, $upload_namespace)
52 5110 acydburn
        {
53 5110 acydburn
                if (!isset($upload_ary))
54 5110 acydburn
                {
55 5110 acydburn
                        $this->init_error = true;
56 5110 acydburn
                        return;
57 5110 acydburn
                }
58 5110 acydburn
59 5110 acydburn
                $this->filename = $upload_ary['tmp_name'];
60 5110 acydburn
                $this->filesize = $upload_ary['size'];
61 10764 git-gate
                $name = (STRIP) ? stripslashes($upload_ary['name']) : $upload_ary['name'];
62 10764 git-gate
                $name = trim(utf8_htmlspecialchars(utf8_basename($name)));
63 10764 git-gate
                $this->realname = $this->uploadname = $name;
64 6945 acydburn
                $this->mimetype = $upload_ary['type'];
65 5110 acydburn
66 5110 acydburn
                // Opera adds the name to the mime type
67 5110 acydburn
                $this->mimetype        = (strpos($this->mimetype, '; name') !== false) ? str_replace(strstr($this->mimetype, '; name'), '', $this->mimetype) : $this->mimetype;
68 5140 acydburn
69 5140 acydburn
                if (!$this->mimetype)
70 5140 acydburn
                {
71 5140 acydburn
                        $this->mimetype = 'application/octetstream';
72 5140 acydburn
                }
73 6058 acydburn
74 5307 acydburn
                $this->extension = strtolower($this->get_extension($this->realname));
75 5110 acydburn
76 5110 acydburn
                // Try to get real filesize from temporary folder (not always working) ;)
77 5110 acydburn
                $this->filesize = (@filesize($this->filename)) ? @filesize($this->filename) : $this->filesize;
78 5110 acydburn
79 5110 acydburn
                $this->width = $this->height = 0;
80 5110 acydburn
                $this->file_moved = false;
81 5110 acydburn
82 5110 acydburn
                $this->local = (isset($upload_ary['local_mode'])) ? true : false;
83 5110 acydburn
                $this->upload = $upload_namespace;
84 5110 acydburn
        }
85 5110 acydburn
86 5110 acydburn
        /**
87 5110 acydburn
        * Cleans destination filename
88 8146 acydburn
        *
89 6831 acydburn
        * @param real|unique|unique_ext $mode real creates a realname, filtering some characters, lowering every character. Unique creates an unique filename
90 5110 acydburn
        * @param string $prefix Prefix applied to filename
91 6058 acydburn
        * @access public
92 5110 acydburn
        */
93 7429 kellanved
        function clean_filename($mode = 'unique', $prefix = '', $user_id = '')
94 5110 acydburn
        {
95 5110 acydburn
                if ($this->init_error)
96 5110 acydburn
                {
97 5110 acydburn
                        return;
98 5110 acydburn
                }
99 6058 acydburn
100 5110 acydburn
                switch ($mode)
101 5110 acydburn
                {
102 5110 acydburn
                        case 'real':
103 5622 acydburn
                                // Remove every extension from filename (to not let the mime bug being exposed)
104 5622 acydburn
                                if (strpos($this->realname, '.') !== false)
105 5622 acydburn
                                {
106 5622 acydburn
                                        $this->realname = substr($this->realname, 0, strpos($this->realname, '.'));
107 5622 acydburn
                                }
108 5622 acydburn
109 5110 acydburn
                                // Replace any chars which may cause us problems with _
110 5110 acydburn
                                $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
111 5135 acydburn
112 5135 acydburn
                                $this->realname = rawurlencode(str_replace($bad_chars, '_', strtolower($this->realname)));
113 5135 acydburn
                                $this->realname = preg_replace("/%(\w{2})/", '_', $this->realname);
114 5135 acydburn
115 5643 acydburn
                                $this->realname = $prefix . $this->realname . '.' . $this->extension;
116 6058 acydburn
                        break;
117 5110 acydburn
118 5110 acydburn
                        case 'unique':
119 6831 acydburn
                                $this->realname = $prefix . md5(unique_id());
120 6831 acydburn
                        break;
121 6831 acydburn
122 7429 kellanved
                        case 'avatar':
123 7453 kellanved
                                $this->extension = strtolower($this->extension);
124 7429 kellanved
                                $this->realname = $prefix . $user_id . '.' . $this->extension;
125 8763 acydburn
126 7429 kellanved
                        break;
127 8763 acydburn
128 6831 acydburn
                        case 'unique_ext':
129 5110 acydburn
                        default:
130 5135 acydburn
                                $this->realname = $prefix . md5(unique_id()) . '.' . $this->extension;
131 6058 acydburn
                        break;
132 5110 acydburn
                }
133 5110 acydburn
        }
134 5110 acydburn
135 6058 acydburn
        /**
136 6058 acydburn
        * Get property from file object
137 6058 acydburn
        */
138 5110 acydburn
        function get($property)
139 5110 acydburn
        {
140 5967 acydburn
                if ($this->init_error || !isset($this->$property))
141 5110 acydburn
                {
142 5110 acydburn
                        return false;
143 5110 acydburn
                }
144 5967 acydburn
145 5110 acydburn
                return $this->$property;
146 5110 acydburn
        }
147 5110 acydburn
148 6058 acydburn
        /**
149 6058 acydburn
        * Check if file is an image (mimetype)
150 6058 acydburn
        *
151 6058 acydburn
        * @return true if it is an image, false if not
152 6058 acydburn
        */
153 5110 acydburn
        function is_image()
154 5110 acydburn
        {
155 5110 acydburn
                return (strpos($this->mimetype, 'image/') !== false) ? true : false;
156 5110 acydburn
        }
157 5110 acydburn
158 6058 acydburn
        /**
159 6058 acydburn
        * Check if the file got correctly uploaded
160 6058 acydburn
        *
161 6414 acydburn
        * @return true if it is a valid upload, false if not
162 6058 acydburn
        */
163 5110 acydburn
        function is_uploaded()
164 5110 acydburn
        {
165 5140 acydburn
                if (!$this->local && !is_uploaded_file($this->filename))
166 5140 acydburn
                {
167 5140 acydburn
                        return false;
168 5140 acydburn
                }
169 5140 acydburn
170 6414 acydburn
                if ($this->local && !file_exists($this->filename))
171 6414 acydburn
                {
172 6414 acydburn
                        return false;
173 6414 acydburn
                }
174 6414 acydburn
175 6414 acydburn
                return true;
176 5110 acydburn
        }
177 5110 acydburn
178 6058 acydburn
        /**
179 6058 acydburn
        * Remove file
180 6058 acydburn
        */
181 5110 acydburn
        function remove()
182 5110 acydburn
        {
183 5110 acydburn
                if ($this->file_moved)
184 5110 acydburn
                {
185 5110 acydburn
                        @unlink($this->destination_file);
186 5110 acydburn
                }
187 5110 acydburn
        }
188 5110 acydburn
189 5110 acydburn
        /**
190 5307 acydburn
        * Get file extension
191 5307 acydburn
        */
192 5307 acydburn
        function get_extension($filename)
193 5307 acydburn
        {
194 5307 acydburn
                if (strpos($filename, '.') === false)
195 5307 acydburn
                {
196 5307 acydburn
                        return '';
197 5307 acydburn
                }
198 5307 acydburn
199 5307 acydburn
                $filename = explode('.', $filename);
200 5307 acydburn
                return array_pop($filename);
201 5307 acydburn
        }
202 5307 acydburn
203 5307 acydburn
        /**
204 6058 acydburn
        * Get mimetype. Utilize mime_content_type if the function exist.
205 6945 acydburn
        * Not used at the moment...
206 5790 acydburn
        */
207 5790 acydburn
        function get_mimetype($filename)
208 5790 acydburn
        {
209 5824 acydburn
                $mimetype = '';
210 5824 acydburn
211 5790 acydburn
                if (function_exists('mime_content_type'))
212 5790 acydburn
                {
213 5790 acydburn
                        $mimetype = mime_content_type($filename);
214 5790 acydburn
                }
215 5790 acydburn
216 5824 acydburn
                // Some browsers choke on a mimetype of application/octet-stream
217 5824 acydburn
                if (!$mimetype || $mimetype == 'application/octet-stream')
218 5790 acydburn
                {
219 5790 acydburn
                        $mimetype = 'application/octetstream';
220 5790 acydburn
                }
221 5790 acydburn
222 5790 acydburn
                return $mimetype;
223 5790 acydburn
        }
224 5790 acydburn
225 5790 acydburn
        /**
226 5790 acydburn
        * Get filesize
227 5790 acydburn
        */
228 5790 acydburn
        function get_filesize($filename)
229 5790 acydburn
        {
230 5790 acydburn
                return @filesize($filename);
231 5790 acydburn
        }
232 8763 acydburn
233 8763 acydburn
234 8555 Kellanved
        /**
235 8555 Kellanved
        * Check the first 256 bytes for forbidden content
236 8555 Kellanved
        */
237 8555 Kellanved
        function check_content($disallowed_content)
238 8555 Kellanved
        {
239 8555 Kellanved
                if (empty($disallowed_content))
240 8555 Kellanved
                {
241 8555 Kellanved
                        return true;
242 8555 Kellanved
                }
243 8763 acydburn
244 8555 Kellanved
                $fp = @fopen($this->filename, 'rb');
245 5790 acydburn
246 8555 Kellanved
                if ($fp !== false)
247 8555 Kellanved
                {
248 8555 Kellanved
                        $ie_mime_relevant = fread($fp, 256);
249 8555 Kellanved
                        fclose($fp);
250 8555 Kellanved
                        foreach ($disallowed_content as $forbidden)
251 8555 Kellanved
                        {
252 8555 Kellanved
                                if (stripos($ie_mime_relevant, '<' . $forbidden) !== false)
253 8555 Kellanved
                                {
254 8555 Kellanved
                                        return false;
255 8555 Kellanved
                                }
256 8555 Kellanved
                        }
257 8555 Kellanved
                }
258 8555 Kellanved
                return true;
259 8555 Kellanved
        }
260 8555 Kellanved
261 5790 acydburn
        /**
262 5110 acydburn
        * Move file to destination folder
263 5110 acydburn
        * The phpbb_root_path variable will be applied to the destination path
264 5110 acydburn
        *
265 5110 acydburn
        * @param string $destination_path Destination path, for example $config['avatar_path']
266 6787 acydburn
        * @param bool $overwrite If set to true, an already existing file will be overwritten
267 8783 acydburn
        * @param string $chmod Permission mask for chmodding the file after a successful move. The mode entered here reflects the mode defined by {@link phpbb_chmod()}
268 8783 acydburn
        *
269 6058 acydburn
        * @access public
270 5110 acydburn
        */
271 8780 acydburn
        function move_file($destination, $overwrite = false, $skip_image_check = false, $chmod = false)
272 5110 acydburn
        {
273 5110 acydburn
                global $user, $phpbb_root_path;
274 5110 acydburn
275 5110 acydburn
                if (sizeof($this->error))
276 5110 acydburn
                {
277 5110 acydburn
                        return false;
278 5110 acydburn
                }
279 5110 acydburn
280 8780 acydburn
                $chmod = ($chmod === false) ? CHMOD_READ | CHMOD_WRITE : $chmod;
281 8780 acydburn
282 6364 acydburn
                // We need to trust the admin in specifying valid upload directories and an attacker not being able to overwrite it...
283 5110 acydburn
                $this->destination_path = $phpbb_root_path . $destination;
284 5110 acydburn
285 6364 acydburn
                // Check if the destination path exist...
286 6364 acydburn
                if (!file_exists($this->destination_path))
287 6364 acydburn
                {
288 6364 acydburn
                        @unlink($this->filename);
289 6364 acydburn
                        return false;
290 6364 acydburn
                }
291 6364 acydburn
292 8522 acydburn
                $upload_mode = (@ini_get('open_basedir') || @ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on') ? 'move' : 'copy';
293 5110 acydburn
                $upload_mode = ($this->local) ? 'local' : $upload_mode;
294 9905 acydburn
                $this->destination_file = $this->destination_path . '/' . utf8_basename($this->realname);
295 5110 acydburn
296 6364 acydburn
                // Check if the file already exist, else there is something wrong...
297 6787 acydburn
                if (file_exists($this->destination_file) && !$overwrite)
298 6364 acydburn
                {
299 6364 acydburn
                        @unlink($this->filename);
300 6364 acydburn
                }
301 6787 acydburn
                else
302 5110 acydburn
                {
303 6787 acydburn
                        if (file_exists($this->destination_file))
304 6787 acydburn
                        {
305 6787 acydburn
                                @unlink($this->destination_file);
306 6787 acydburn
                        }
307 6058 acydburn
308 6787 acydburn
                        switch ($upload_mode)
309 6787 acydburn
                        {
310 6787 acydburn
                                case 'copy':
311 6787 acydburn
312 8146 acydburn
                                        if (!@copy($this->filename, $this->destination_file))
313 6787 acydburn
                                        {
314 8146 acydburn
                                                if (!@move_uploaded_file($this->filename, $this->destination_file))
315 6787 acydburn
                                                {
316 6787 acydburn
                                                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
317 6787 acydburn
                                                }
318 6787 acydburn
                                        }
319 6787 acydburn
320 6787 acydburn
                                break;
321 6787 acydburn
322 6787 acydburn
                                case 'move':
323 6787 acydburn
324 8146 acydburn
                                        if (!@move_uploaded_file($this->filename, $this->destination_file))
325 5110 acydburn
                                        {
326 8146 acydburn
                                                if (!@copy($this->filename, $this->destination_file))
327 6787 acydburn
                                                {
328 6787 acydburn
                                                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
329 6787 acydburn
                                                }
330 5110 acydburn
                                        }
331 6787 acydburn
332 6787 acydburn
                                break;
333 6058 acydburn
334 6787 acydburn
                                case 'local':
335 6058 acydburn
336 8146 acydburn
                                        if (!@copy($this->filename, $this->destination_file))
337 5110 acydburn
                                        {
338 5110 acydburn
                                                $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
339 5110 acydburn
                                        }
340 5110 acydburn
341 6787 acydburn
                                break;
342 6787 acydburn
                        }
343 6058 acydburn
344 10122 acydburn
                        // Remove temporary filename
345 10122 acydburn
                        @unlink($this->filename);
346 10122 acydburn
347 10122 acydburn
                        if (sizeof($this->error))
348 10122 acydburn
                        {
349 10122 acydburn
                                return false;
350 10122 acydburn
                        }
351 10122 acydburn
352 8780 acydburn
                        phpbb_chmod($this->destination_file, $chmod);
353 5110 acydburn
                }
354 5110 acydburn
355 5110 acydburn
                // Try to get real filesize from destination folder
356 5110 acydburn
                $this->filesize = (@filesize($this->destination_file)) ? @filesize($this->destination_file) : $this->filesize;
357 5110 acydburn
358 7616 acydburn
                if ($this->is_image() && !$skip_image_check)
359 5110 acydburn
                {
360 6058 acydburn
                        $this->width = $this->height = 0;
361 6058 acydburn
362 7646 acydburn
                        if (($this->image_info = @getimagesize($this->destination_file)) !== false)
363 6058 acydburn
                        {
364 6058 acydburn
                                $this->width = $this->image_info[0];
365 6058 acydburn
                                $this->height = $this->image_info[1];
366 6058 acydburn
367 6058 acydburn
                                if (!empty($this->image_info['mime']))
368 6058 acydburn
                                {
369 6058 acydburn
                                        $this->mimetype = $this->image_info['mime'];
370 6058 acydburn
                                }
371 6354 acydburn
372 6354 acydburn
                                // Check image type
373 6354 acydburn
                                $types = $this->upload->image_types();
374 6354 acydburn
375 6354 acydburn
                                if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]]))
376 6354 acydburn
                                {
377 6354 acydburn
                                        if (!isset($types[$this->image_info[2]]))
378 6354 acydburn
                                        {
379 6354 acydburn
                                                $this->error[] = sprintf($user->lang['IMAGE_FILETYPE_INVALID'], $this->image_info[2], $this->mimetype);
380 6354 acydburn
                                        }
381 6354 acydburn
                                        else
382 6354 acydburn
                                        {
383 6354 acydburn
                                                $this->error[] = sprintf($user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$this->image_info[2]][0], $this->extension);
384 6354 acydburn
                                        }
385 6354 acydburn
                                }
386 7150 acydburn
387 7150 acydburn
                                // Make sure the dimensions match a valid image
388 7501 kellanved
                                if (empty($this->width) || empty($this->height))
389 7150 acydburn
                                {
390 7150 acydburn
                                        $this->error[] = $user->lang['ATTACHED_IMAGE_NOT_IMAGE'];
391 7150 acydburn
                                }
392 6058 acydburn
                        }
393 6354 acydburn
                        else
394 6354 acydburn
                        {
395 6354 acydburn
                                $this->error[] = $user->lang['UNABLE_GET_IMAGE_SIZE'];
396 6354 acydburn
                        }
397 5110 acydburn
                }
398 5110 acydburn
399 5110 acydburn
                $this->file_moved = true;
400 5110 acydburn
                $this->additional_checks();
401 5110 acydburn
                unset($this->upload);
402 5967 acydburn
403 5967 acydburn
                return true;
404 5110 acydburn
        }
405 5110 acydburn
406 6058 acydburn
        /**
407 6058 acydburn
        * Performing additional checks
408 6058 acydburn
        */
409 5110 acydburn
        function additional_checks()
410 5110 acydburn
        {
411 5110 acydburn
                global $user;
412 5110 acydburn
413 5110 acydburn
                if (!$this->file_moved)
414 5110 acydburn
                {
415 5110 acydburn
                        return false;
416 5110 acydburn
                }
417 6058 acydburn
418 5110 acydburn
                // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form
419 5110 acydburn
                if ($this->upload->max_filesize && ($this->get('filesize') > $this->upload->max_filesize || $this->filesize == 0))
420 5110 acydburn
                {
421 8389 acydburn
                        $max_filesize = get_formatted_filesize($this->upload->max_filesize, false);
422 8763 acydburn
423 9748 bantu
                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
424 5967 acydburn
425 5967 acydburn
                        return false;
426 5110 acydburn
                }
427 5110 acydburn
428 5110 acydburn
                if (!$this->upload->valid_dimensions($this))
429 5110 acydburn
                {
430 5952 acydburn
                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_SIZE'], $this->upload->min_width, $this->upload->min_height, $this->upload->max_width, $this->upload->max_height, $this->width, $this->height);
431 5967 acydburn
432 5967 acydburn
                        return false;
433 5110 acydburn
                }
434 5967 acydburn
435 5967 acydburn
                return true;
436 5110 acydburn
        }
437 5110 acydburn
}
438 5110 acydburn
439 5114 acydburn
/**
440 6058 acydburn
* Class for assigning error messages before a real filespec class can be assigned
441 6058 acydburn
*
442 5114 acydburn
* @package phpBB3
443 5114 acydburn
*/
444 5110 acydburn
class fileerror extends filespec
445 5110 acydburn
{
446 5110 acydburn
        function fileerror($error_msg)
447 5110 acydburn
        {
448 5110 acydburn
                $this->error[] = $error_msg;
449 5110 acydburn
        }
450 5110 acydburn
}
451 5110 acydburn
452 5114 acydburn
/**
453 5114 acydburn
* File upload class
454 7266 acydburn
* Init class (all parameters optional and able to be set/overwritten separately) - scope is global and valid for all uploads
455 5114 acydburn
*
456 6058 acydburn
* @package phpBB3
457 5114 acydburn
*/
458 5110 acydburn
class fileupload
459 5110 acydburn
{
460 5110 acydburn
        var $allowed_extensions = array();
461 10923 git-gate
        var $disallowed_content = array('body', 'head', 'html', 'img', 'plaintext', 'a href', 'pre', 'script', 'table', 'title');
462 5110 acydburn
        var $max_filesize = 0;
463 5110 acydburn
        var $min_width = 0;
464 5110 acydburn
        var $min_height = 0;
465 5110 acydburn
        var $max_width = 0;
466 5110 acydburn
        var $max_height = 0;
467 5110 acydburn
        var $error_prefix = '';
468 5110 acydburn
469 5110 acydburn
        /**
470 6058 acydburn
        * Init file upload class.
471 5110 acydburn
        *
472 5110 acydburn
        * @param string $error_prefix Used error messages will get prefixed by this string
473 5110 acydburn
        * @param array $allowed_extensions Array of allowed extensions, for example array('jpg', 'jpeg', 'gif', 'png')
474 5110 acydburn
        * @param int $max_filesize Maximum filesize
475 5110 acydburn
        * @param int $min_width Minimum image width (only checked for images)
476 5110 acydburn
        * @param int $min_height Minimum image height (only checked for images)
477 5110 acydburn
        * @param int $max_width Maximum image width (only checked for images)
478 5110 acydburn
        * @param int $max_height Maximum image height (only checked for images)
479 5110 acydburn
        *
480 5110 acydburn
        */
481 8555 Kellanved
        function fileupload($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)
482 5110 acydburn
        {
483 5110 acydburn
                $this->set_allowed_extensions($allowed_extensions);
484 5110 acydburn
                $this->set_max_filesize($max_filesize);
485 5110 acydburn
                $this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height);
486 5110 acydburn
                $this->set_error_prefix($error_prefix);
487 8555 Kellanved
                $this->set_disallowed_content($disallowed_content);
488 5110 acydburn
        }
489 5110 acydburn
490 6058 acydburn
        /**
491 6058 acydburn
        * Reset vars
492 6058 acydburn
        */
493 5110 acydburn
        function reset_vars()
494 5110 acydburn
        {
495 5110 acydburn
                $this->max_filesize = 0;
496 5110 acydburn
                $this->min_width = $this->min_height = $this->max_width = $this->max_height = 0;
497 5110 acydburn
                $this->error_prefix = '';
498 5110 acydburn
                $this->allowed_extensions = array();
499 8555 Kellanved
                $this->disallowed_content = array();
500 5110 acydburn
        }
501 5110 acydburn
502 6058 acydburn
        /**
503 6058 acydburn
        * Set allowed extensions
504 6058 acydburn
        */
505 5110 acydburn
        function set_allowed_extensions($allowed_extensions)
506 5110 acydburn
        {
507 5110 acydburn
                if ($allowed_extensions !== false && is_array($allowed_extensions))
508 5110 acydburn
                {
509 5110 acydburn
                        $this->allowed_extensions = $allowed_extensions;
510 5110 acydburn
                }
511 5110 acydburn
        }
512 5110 acydburn
513 6058 acydburn
        /**
514 6058 acydburn
        * Set allowed dimensions
515 6058 acydburn
        */
516 5110 acydburn
        function set_allowed_dimensions($min_width, $min_height, $max_width, $max_height)
517 5110 acydburn
        {
518 5110 acydburn
                $this->min_width = (int) $min_width;
519 5110 acydburn
                $this->min_height = (int) $min_height;
520 5110 acydburn
                $this->max_width = (int) $max_width;
521 5110 acydburn
                $this->max_height = (int) $max_height;
522 5110 acydburn
        }
523 5110 acydburn
524 6058 acydburn
        /**
525 6058 acydburn
        * Set maximum allowed filesize
526 6058 acydburn
        */
527 5110 acydburn
        function set_max_filesize($max_filesize)
528 5110 acydburn
        {
529 5110 acydburn
                if ($max_filesize !== false && (int) $max_filesize)
530 5110 acydburn
                {
531 5110 acydburn
                        $this->max_filesize = (int) $max_filesize;
532 5110 acydburn
                }
533 5110 acydburn
        }
534 8763 acydburn
535 8555 Kellanved
        /**
536 8555 Kellanved
        * Set disallowed strings
537 8555 Kellanved
        */
538 8555 Kellanved
        function set_disallowed_content($disallowed_content)
539 8555 Kellanved
        {
540 8555 Kellanved
                if ($disallowed_content !== false && is_array($disallowed_content))
541 8555 Kellanved
                {
542 10923 git-gate
                        $this->disallowed_content = array_diff($disallowed_content, array(''));
543 8555 Kellanved
                }
544 8555 Kellanved
        }
545 5110 acydburn
546 6058 acydburn
        /**
547 6058 acydburn
        * Set error prefix
548 6058 acydburn
        */
549 5110 acydburn
        function set_error_prefix($error_prefix)
550 5110 acydburn
        {
551 5110 acydburn
                $this->error_prefix = $error_prefix;
552 5110 acydburn
        }
553 5110 acydburn
554 5110 acydburn
        /**
555 5110 acydburn
        * Form upload method
556 5110 acydburn
        * Upload file from users harddisk
557 5110 acydburn
        *
558 5110 acydburn
        * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified)
559 5110 acydburn
        * @return object $file Object "filespec" is returned, all further operations can be done with this object
560 6058 acydburn
        * @access public
561 5110 acydburn
        */
562 5110 acydburn
        function form_upload($form_name)
563 5110 acydburn
        {
564 5110 acydburn
                global $user;
565 5110 acydburn
566 5110 acydburn
                unset($_FILES[$form_name]['local_mode']);
567 5110 acydburn
                $file = new filespec($_FILES[$form_name], $this);
568 5110 acydburn
569 5110 acydburn
                if ($file->init_error)
570 5110 acydburn
                {
571 5110 acydburn
                        $file->error[] = '';
572 5110 acydburn
                        return $file;
573 5110 acydburn
                }
574 6058 acydburn
575 5147 acydburn
                // Error array filled?
576 5110 acydburn
                if (isset($_FILES[$form_name]['error']))
577 5110 acydburn
                {
578 5110 acydburn
                        $error = $this->assign_internal_error($_FILES[$form_name]['error']);
579 5110 acydburn
580 5110 acydburn
                        if ($error !== false)
581 5110 acydburn
                        {
582 5110 acydburn
                                $file->error[] = $error;
583 5110 acydburn
                                return $file;
584 5110 acydburn
                        }
585 5110 acydburn
                }
586 5110 acydburn
587 5147 acydburn
                // Check if empty file got uploaded (not catched by is_uploaded_file)
588 5147 acydburn
                if (isset($_FILES[$form_name]['size']) && $_FILES[$form_name]['size'] == 0)
589 5147 acydburn
                {
590 5147 acydburn
                        $file->error[] = $user->lang[$this->error_prefix . 'EMPTY_FILEUPLOAD'];
591 5147 acydburn
                        return $file;
592 5147 acydburn
                }
593 5147 acydburn
594 5110 acydburn
                // PHP Upload filesize exceeded
595 5110 acydburn
                if ($file->get('filename') == 'none')
596 5110 acydburn
                {
597 9464 acydburn
                        $max_filesize = @ini_get('upload_max_filesize');
598 9464 acydburn
                        $unit = 'MB';
599 9464 acydburn
600 9464 acydburn
                        if (!empty($max_filesize))
601 9464 acydburn
                        {
602 9464 acydburn
                                $unit = strtolower(substr($max_filesize, -1, 1));
603 9464 acydburn
                                $max_filesize = (int) $max_filesize;
604 9464 acydburn
605 9464 acydburn
                                $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
606 9464 acydburn
                        }
607 9464 acydburn
608 9464 acydburn
                        $file->error[] = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
609 5110 acydburn
                        return $file;
610 5110 acydburn
                }
611 5110 acydburn
612 5110 acydburn
                // Not correctly uploaded
613 5110 acydburn
                if (!$file->is_uploaded())
614 5110 acydburn
                {
615 5110 acydburn
                        $file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED'];
616 5110 acydburn
                        return $file;
617 5110 acydburn
                }
618 5110 acydburn
619 5110 acydburn
                $this->common_checks($file);
620 5110 acydburn
621 5110 acydburn
                return $file;
622 5110 acydburn
        }
623 5110 acydburn
624 6058 acydburn
        /**
625 6058 acydburn
        * Move file from another location to phpBB
626 6058 acydburn
        */
627 5140 acydburn
        function local_upload($source_file, $filedata = false)
628 5110 acydburn
        {
629 5140 acydburn
                global $user;
630 5140 acydburn
631 5140 acydburn
                $form_name = 'local';
632 5140 acydburn
633 5140 acydburn
                $_FILES[$form_name]['local_mode'] = true;
634 5140 acydburn
                $_FILES[$form_name]['tmp_name'] = $source_file;
635 5140 acydburn
636 5140 acydburn
                if ($filedata === false)
637 5140 acydburn
                {
638 9905 acydburn
                        $_FILES[$form_name]['name'] = utf8_basename($source_file);
639 5140 acydburn
                        $_FILES[$form_name]['size'] = 0;
640 6975 acydburn
                        $mimetype = '';
641 6975 acydburn
642 6975 acydburn
                        if (function_exists('mime_content_type'))
643 6975 acydburn
                        {
644 8087 acydburn
                                $mimetype = mime_content_type($source_file);
645 6975 acydburn
                        }
646 6975 acydburn
647 6975 acydburn
                        // Some browsers choke on a mimetype of application/octet-stream
648 6975 acydburn
                        if (!$mimetype || $mimetype == 'application/octet-stream')
649 6975 acydburn
                        {
650 6975 acydburn
                                $mimetype = 'application/octetstream';
651 6975 acydburn
                        }
652 6975 acydburn
653 6975 acydburn
                        $_FILES[$form_name]['type'] = $mimetype;
654 5140 acydburn
                }
655 5140 acydburn
                else
656 5140 acydburn
                {
657 5140 acydburn
                        $_FILES[$form_name]['name'] = $filedata['realname'];
658 5140 acydburn
                        $_FILES[$form_name]['size'] = $filedata['size'];
659 5140 acydburn
                        $_FILES[$form_name]['type'] = $filedata['type'];
660 6058 acydburn
                }
661 5140 acydburn
662 5140 acydburn
                $file = new filespec($_FILES[$form_name], $this);
663 5140 acydburn
664 5140 acydburn
                if ($file->init_error)
665 5140 acydburn
                {
666 5140 acydburn
                        $file->error[] = '';
667 5140 acydburn
                        return $file;
668 5140 acydburn
                }
669 6058 acydburn
670 5140 acydburn
                if (isset($_FILES[$form_name]['error']))
671 5140 acydburn
                {
672 5140 acydburn
                        $error = $this->assign_internal_error($_FILES[$form_name]['error']);
673 5140 acydburn
674 5140 acydburn
                        if ($error !== false)
675 5140 acydburn
                        {
676 5140 acydburn
                                $file->error[] = $error;
677 5140 acydburn
                                return $file;
678 5140 acydburn
                        }
679 5140 acydburn
                }
680 5140 acydburn
681 5140 acydburn
                // PHP Upload filesize exceeded
682 5140 acydburn
                if ($file->get('filename') == 'none')
683 5140 acydburn
                {
684 9464 acydburn
                        $max_filesize = @ini_get('upload_max_filesize');
685 9464 acydburn
                        $unit = 'MB';
686 9464 acydburn
687 9464 acydburn
                        if (!empty($max_filesize))
688 9464 acydburn
                        {
689 9464 acydburn
                                $unit = strtolower(substr($max_filesize, -1, 1));
690 9464 acydburn
                                $max_filesize = (int) $max_filesize;
691 9464 acydburn
692 9464 acydburn
                                $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
693 9464 acydburn
                        }
694 9464 acydburn
695 9464 acydburn
                        $file->error[] = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
696 5140 acydburn
                        return $file;
697 5140 acydburn
                }
698 5140 acydburn
699 5140 acydburn
                // Not correctly uploaded
700 5140 acydburn
                if (!$file->is_uploaded())
701 5140 acydburn
                {
702 5140 acydburn
                        $file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED'];
703 5140 acydburn
                        return $file;
704 5140 acydburn
                }
705 5140 acydburn
706 5140 acydburn
                $this->common_checks($file);
707 5140 acydburn
708 5140 acydburn
                return $file;
709 5110 acydburn
        }
710 5110 acydburn
711 5110 acydburn
        /**
712 5110 acydburn
        * Remote upload method
713 5110 acydburn
        * Uploads file from given url
714 5110 acydburn
        *
715 5110 acydburn
        * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
716 5110 acydburn
        * @return object $file Object "filespec" is returned, all further operations can be done with this object
717 6058 acydburn
        * @access public
718 5110 acydburn
        */
719 5110 acydburn
        function remote_upload($upload_url)
720 5110 acydburn
        {
721 5110 acydburn
                global $user, $phpbb_root_path;
722 6058 acydburn
723 5110 acydburn
                $upload_ary = array();
724 5110 acydburn
                $upload_ary['local_mode'] = true;
725 5110 acydburn
726 6058 acydburn
                if (!preg_match('#^(https?://).*?\.(' . implode('|', $this->allowed_extensions) . ')$#i', $upload_url, $match))
727 5110 acydburn
                {
728 5110 acydburn
                        $file = new fileerror($user->lang[$this->error_prefix . 'URL_INVALID']);
729 5110 acydburn
                        return $file;
730 5110 acydburn
                }
731 8146 acydburn
732 5110 acydburn
                if (empty($match[2]))
733 5110 acydburn
                {
734 5110 acydburn
                        $file = new fileerror($user->lang[$this->error_prefix . 'URL_INVALID']);
735 5110 acydburn
                        return $file;
736 5110 acydburn
                }
737 5110 acydburn
738 5110 acydburn
                $url = parse_url($upload_url);
739 5110 acydburn
740 5110 acydburn
                $host = $url['host'];
741 5765 acydburn
                $path = $url['path'];
742 5189 acydburn
                $port = (!empty($url['port'])) ? (int) $url['port'] : 80;
743 6058 acydburn
744 5110 acydburn
                $upload_ary['type'] = 'application/octet-stream';
745 6058 acydburn
746 5307 acydburn
                $url['path'] = explode('.', $url['path']);
747 5307 acydburn
                $ext = array_pop($url['path']);
748 6058 acydburn
749 5749 acydburn
                $url['path'] = implode('', $url['path']);
750 9905 acydburn
                $upload_ary['name'] = utf8_basename($url['path']) . (($ext) ? '.' . $ext : '');
751 5110 acydburn
                $filename = $url['path'];
752 5110 acydburn
                $filesize = 0;
753 5110 acydburn
754 6846 acydburn
                $errno = 0;
755 6846 acydburn
                $errstr = '';
756 6846 acydburn
757 5110 acydburn
                if (!($fsock = @fsockopen($host, $port, $errno, $errstr)))
758 5110 acydburn
                {
759 5110 acydburn
                        $file = new fileerror($user->lang[$this->error_prefix . 'NOT_UPLOADED']);
760 5110 acydburn
                        return $file;
761 5110 acydburn
                }
762 5110 acydburn
763 7608 acydburn
                // Make sure $path not beginning with /
764 7608 acydburn
                if (strpos($path, '/') === 0)
765 7608 acydburn
                {
766 7608 acydburn
                        $path = substr($path, 1);
767 7608 acydburn
                }
768 7608 acydburn
769 5765 acydburn
                fputs($fsock, 'GET /' . $path . " HTTP/1.1\r\n");
770 5110 acydburn
                fputs($fsock, "HOST: " . $host . "\r\n");
771 5110 acydburn
                fputs($fsock, "Connection: close\r\n\r\n");
772 5110 acydburn
773 5110 acydburn
                $get_info = false;
774 5110 acydburn
                $data = '';
775 5110 acydburn
                while (!@feof($fsock))
776 5110 acydburn
                {
777 5110 acydburn
                        if ($get_info)
778 5110 acydburn
                        {
779 10605 git-gate
                                $block = @fread($fsock, 1024);
780 10605 git-gate
                                $filesize += strlen($block);
781 10605 git-gate
782 10605 git-gate
                                if ($this->max_filesize && $filesize > $this->max_filesize)
783 10605 git-gate
                                {
784 10605 git-gate
                                        $max_filesize = get_formatted_filesize($this->max_filesize, false);
785 10605 git-gate
786 10605 git-gate
                                        $file = new fileerror(sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']));
787 10605 git-gate
                                        return $file;
788 10605 git-gate
                                }
789 10605 git-gate
790 10605 git-gate
                                $data .= $block;
791 5110 acydburn
                        }
792 5110 acydburn
                        else
793 5110 acydburn
                        {
794 5110 acydburn
                                $line = @fgets($fsock, 1024);
795 5110 acydburn
796 5110 acydburn
                                if ($line == "\r\n")
797 5110 acydburn
                                {
798 5110 acydburn
                                        $get_info = true;
799 5110 acydburn
                                }
800 5110 acydburn
                                else
801 5110 acydburn
                                {
802 6846 acydburn
                                        if (stripos($line, 'content-type: ') !== false)
803 5110 acydburn
                                        {
804 6846 acydburn
                                                $upload_ary['type'] = rtrim(str_replace('content-type: ', '', strtolower($line)));
805 5110 acydburn
                                        }
806 10605 git-gate
                                        else if ($this->max_filesize && stripos($line, 'content-length: ') !== false)
807 10605 git-gate
                                        {
808 10605 git-gate
                                                $length = (int) str_replace('content-length: ', '', strtolower($line));
809 10605 git-gate
810 10605 git-gate
                                                if ($length && $length > $this->max_filesize)
811 10605 git-gate
                                                {
812 10605 git-gate
                                                        $max_filesize = get_formatted_filesize($this->max_filesize, false);
813 10605 git-gate
814 10605 git-gate
                                                        $file = new fileerror(sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']));
815 10605 git-gate
                                                        return $file;
816 10605 git-gate
                                                }
817 10605 git-gate
                                        }
818 6846 acydburn
                                        else if (stripos($line, '404 not found') !== false)
819 5765 acydburn
                                        {
820 5765 acydburn
                                                $file = new fileerror($user->lang[$this->error_prefix . 'URL_NOT_FOUND']);
821 5765 acydburn
                                                return $file;
822 5765 acydburn
                                        }
823 5110 acydburn
                                }
824 5110 acydburn
                        }
825 5110 acydburn
                }
826 5110 acydburn
                @fclose($fsock);
827 5110 acydburn
828 5110 acydburn
                if (empty($data))
829 5110 acydburn
                {
830 5110 acydburn
                        $file = new fileerror($user->lang[$this->error_prefix . 'EMPTY_REMOTE_DATA']);
831 5110 acydburn
                        return $file;
832 5110 acydburn
                }
833 5110 acydburn
834 8522 acydburn
                $tmp_path = (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') ? false : $phpbb_root_path . 'cache';
835 5622 acydburn
                $filename = tempnam($tmp_path, unique_id() . '-');
836 5110 acydburn
837 5110 acydburn
                if (!($fp = @fopen($filename, 'wb')))
838 5110 acydburn
                {
839 5110 acydburn
                        $file = new fileerror($user->lang[$this->error_prefix . 'NOT_UPLOADED']);
840 5110 acydburn
                        return $file;
841 5110 acydburn
                }
842 6058 acydburn
843 5110 acydburn
                $upload_ary['size'] = fwrite($fp, $data);
844 5110 acydburn
                fclose($fp);
845 5110 acydburn
                unset($data);
846 5110 acydburn
847 5110 acydburn
                $upload_ary['tmp_name'] = $filename;
848 5110 acydburn
849 5110 acydburn
                $file = new filespec($upload_ary, $this);
850 5110 acydburn
                $this->common_checks($file);
851 5110 acydburn
852 5110 acydburn
                return $file;
853 5110 acydburn
        }
854 5110 acydburn
855 6058 acydburn
        /**
856 6058 acydburn
        * Assign internal error
857 6058 acydburn
        * @access private
858 6058 acydburn
        */
859 5110 acydburn
        function assign_internal_error($errorcode)
860 5110 acydburn
        {
861 5110 acydburn
                global $user;
862 5110 acydburn
863 5110 acydburn
                switch ($errorcode)
864 5110 acydburn
                {
865 5110 acydburn
                        case 1:
866 9464 acydburn
                                $max_filesize = @ini_get('upload_max_filesize');
867 9464 acydburn
                                $unit = 'MB';
868 9464 acydburn
869 9464 acydburn
                                if (!empty($max_filesize))
870 9464 acydburn
                                {
871 9464 acydburn
                                        $unit = strtolower(substr($max_filesize, -1, 1));
872 9464 acydburn
                                        $max_filesize = (int) $max_filesize;
873 9464 acydburn
874 9464 acydburn
                                        $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
875 9464 acydburn
                                }
876 9464 acydburn
877 9464 acydburn
                                $error = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
878 5765 acydburn
                        break;
879 5765 acydburn
880 5110 acydburn
                        case 2:
881 8389 acydburn
                                $max_filesize = get_formatted_filesize($this->max_filesize, false);
882 5765 acydburn
883 9748 bantu
                                $error = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
884 5765 acydburn
                        break;
885 5765 acydburn
886 5110 acydburn
                        case 3:
887 6058 acydburn
                                $error = $user->lang[$this->error_prefix . 'PARTIAL_UPLOAD'];
888 6058 acydburn
                        break;
889 6058 acydburn
890 5110 acydburn
                        case 4:
891 5110 acydburn
                                $error = $user->lang[$this->error_prefix . 'NOT_UPLOADED'];
892 6058 acydburn
                        break;
893 6058 acydburn
894 5110 acydburn
                        case 6:
895 5110 acydburn
                                $error = 'Temporary folder could not be found. Please check your PHP installation.';
896 6058 acydburn
                        break;
897 6058 acydburn
898 5110 acydburn
                        default:
899 5110 acydburn
                                $error = false;
900 6058 acydburn
                        break;
901 5110 acydburn
                }
902 5110 acydburn
903 5110 acydburn
                return $error;
904 5110 acydburn
        }
905 6058 acydburn
906 6058 acydburn
        /**
907 6058 acydburn
        * Perform common checks
908 6058 acydburn
        */
909 5110 acydburn
        function common_checks(&$file)
910 5110 acydburn
        {
911 5110 acydburn
                global $user;
912 5110 acydburn
913 5110 acydburn
                // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form
914 5110 acydburn
                if ($this->max_filesize && ($file->get('filesize') > $this->max_filesize || $file->get('filesize') == 0))
915 5110 acydburn
                {
916 8389 acydburn
                        $max_filesize = get_formatted_filesize($this->max_filesize, false);
917 5765 acydburn
918 9748 bantu
                        $file->error[] = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
919 5110 acydburn
                }
920 5110 acydburn
921 5110 acydburn
                // check Filename
922 5110 acydburn
                if (preg_match("#[\\/:*?\"<>|]#i", $file->get('realname')))
923 8146 acydburn
                {
924 5110 acydburn
                        $file->error[] = sprintf($user->lang[$this->error_prefix . 'INVALID_FILENAME'], $file->get('realname'));
925 5110 acydburn
                }
926 5110 acydburn
927 5110 acydburn
                // Invalid Extension
928 5110 acydburn
                if (!$this->valid_extension($file))
929 5110 acydburn
                {
930 5110 acydburn
                        $file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_EXTENSION'], $file->get('extension'));
931 5110 acydburn
                }
932 8763 acydburn
933 8555 Kellanved
                // MIME Sniffing
934 8555 Kellanved
                if (!$this->valid_content($file))
935 8555 Kellanved
                {
936 8555 Kellanved
                        $file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_CONTENT']);
937 8555 Kellanved
                }
938 5110 acydburn
        }
939 5110 acydburn
940 6058 acydburn
        /**
941 6058 acydburn
        * Check for allowed extension
942 6058 acydburn
        */
943 5110 acydburn
        function valid_extension(&$file)
944 5110 acydburn
        {
945 5110 acydburn
                return (in_array($file->get('extension'), $this->allowed_extensions)) ? true : false;
946 5110 acydburn
        }
947 5110 acydburn
948 6058 acydburn
        /**
949 6058 acydburn
        * Check for allowed dimension
950 6058 acydburn
        */
951 5110 acydburn
        function valid_dimensions(&$file)
952 5110 acydburn
        {
953 5135 acydburn
                if (!$this->max_width && !$this->max_height && !$this->min_width && !$this->min_height)
954 5135 acydburn
                {
955 5135 acydburn
                        return true;
956 5135 acydburn
                }
957 6058 acydburn
958 8146 acydburn
                if (($file->get('width') > $this->max_width && $this->max_width) ||
959 8146 acydburn
                        ($file->get('height') > $this->max_height && $this->max_height) ||
960 5110 acydburn
                        ($file->get('width') < $this->min_width && $this->min_width) ||
961 5135 acydburn
                        ($file->get('height') < $this->min_height && $this->min_height))
962 5110 acydburn
                {
963 5110 acydburn
                        return false;
964 5110 acydburn
                }
965 5110 acydburn
966 5110 acydburn
                return true;
967 5110 acydburn
        }
968 5110 acydburn
969 6058 acydburn
        /**
970 6058 acydburn
        * Check if form upload is valid
971 6058 acydburn
        */
972 5110 acydburn
        function is_valid($form_name)
973 5110 acydburn
        {
974 5110 acydburn
                return (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none') ? true : false;
975 5110 acydburn
        }
976 6354 acydburn
977 8555 Kellanved
978 6354 acydburn
        /**
979 8555 Kellanved
        * Check for allowed extension
980 8555 Kellanved
        */
981 8555 Kellanved
        function valid_content(&$file)
982 8555 Kellanved
        {
983 8555 Kellanved
                return ($file->check_content($this->disallowed_content));
984 8555 Kellanved
        }
985 8555 Kellanved
986 8555 Kellanved
        /**
987 8146 acydburn
        * Return image type/extension mapping
988 6354 acydburn
        */
989 6354 acydburn
        function image_types()
990 6354 acydburn
        {
991 6354 acydburn
                return array(
992 6354 acydburn
                        1 => array('gif'),
993 6354 acydburn
                        2 => array('jpg', 'jpeg'),
994 6354 acydburn
                        3 => array('png'),
995 6354 acydburn
                        4 => array('swf'),
996 6354 acydburn
                        5 => array('psd'),
997 6354 acydburn
                        6 => array('bmp'),
998 6354 acydburn
                        7 => array('tif', 'tiff'),
999 6354 acydburn
                        8 => array('tif', 'tiff'),
1000 6354 acydburn
                        9 => array('jpg', 'jpeg'),
1001 6354 acydburn
                        10 => array('jpg', 'jpeg'),
1002 6354 acydburn
                        11 => array('jpg', 'jpeg'),
1003 6354 acydburn
                        12 => array('jpg', 'jpeg'),
1004 6354 acydburn
                        13 => array('swc'),
1005 6354 acydburn
                        14 => array('iff'),
1006 6354 acydburn
                        15 => array('wbmp'),
1007 6354 acydburn
                        16 => array('xbm'),
1008 6354 acydburn
                );
1009 6354 acydburn
        }
1010 5110 acydburn
}
1011 5110 acydburn
1012 5110 acydburn
?>