Update code_sniffer build.xml file to be executable on our system
[phpbb.git] / phpBB / includes / functions_upload.php
blob363bfdd76872f1fde35e1c2301d65a882ce19bae
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * Responsible for holding all file relevant information, as well as doing file-specific operations.
21 * The {@link fileupload fileupload class} can be used to upload several files, each of them being this object to operate further on.
22 * @package phpBB3
24 class filespec
26 var $filename = '';
27 var $realname = '';
28 var $uploadname = '';
29 var $mimetype = '';
30 var $extension = '';
31 var $filesize = 0;
32 var $width = 0;
33 var $height = 0;
34 var $image_info = array();
36 var $destination_file = '';
37 var $destination_path = '';
39 var $file_moved = false;
40 var $init_error = false;
41 var $local = false;
43 var $error = array();
45 var $upload = '';
47 /**
48 * File Class
49 * @access private
51 function __construct($upload_ary, $upload_namespace)
53 if (!isset($upload_ary))
55 $this->init_error = true;
56 return;
59 $this->filename = $upload_ary['tmp_name'];
60 $this->filesize = $upload_ary['size'];
61 $name = trim(htmlspecialchars(basename($upload_ary['name'])));
62 $this->realname = $this->uploadname = (STRIP) ? stripslashes($name) : $name;
63 $this->mimetype = $upload_ary['type'];
65 // Opera adds the name to the mime type
66 $this->mimetype = (strpos($this->mimetype, '; name') !== false) ? str_replace(strstr($this->mimetype, '; name'), '', $this->mimetype) : $this->mimetype;
68 if (!$this->mimetype)
70 $this->mimetype = 'application/octetstream';
73 $this->extension = strtolower($this->get_extension($this->realname));
75 // Try to get real filesize from temporary folder (not always working) ;)
76 $this->filesize = (@filesize($this->filename)) ? @filesize($this->filename) : $this->filesize;
78 $this->width = $this->height = 0;
79 $this->file_moved = false;
81 $this->local = (isset($upload_ary['local_mode'])) ? true : false;
82 $this->upload = $upload_namespace;
85 /**
86 * Cleans destination filename
88 * @param real|unique|unique_ext $mode real creates a realname, filtering some characters, lowering every character. Unique creates an unique filename
89 * @param string $prefix Prefix applied to filename
90 * @access public
92 function clean_filename($mode = 'unique', $prefix = '', $user_id = '')
94 if ($this->init_error)
96 return;
99 switch ($mode)
101 case 'real':
102 // Remove every extension from filename (to not let the mime bug being exposed)
103 if (strpos($this->realname, '.') !== false)
105 $this->realname = substr($this->realname, 0, strpos($this->realname, '.'));
108 // Replace any chars which may cause us problems with _
109 $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
111 $this->realname = rawurlencode(str_replace($bad_chars, '_', strtolower($this->realname)));
112 $this->realname = preg_replace("/%(\w{2})/", '_', $this->realname);
114 $this->realname = $prefix . $this->realname . '.' . $this->extension;
115 break;
117 case 'unique':
118 $this->realname = $prefix . md5(unique_id());
119 break;
121 case 'avatar':
122 $this->extension = strtolower($this->extension);
123 $this->realname = $prefix . $user_id . '.' . $this->extension;
125 break;
127 case 'unique_ext':
128 default:
129 $this->realname = $prefix . md5(unique_id()) . '.' . $this->extension;
130 break;
135 * Get property from file object
137 function get($property)
139 if ($this->init_error || !isset($this->$property))
141 return false;
144 return $this->$property;
148 * Check if file is an image (mimetype)
150 * @return true if it is an image, false if not
152 function is_image()
154 return (strpos($this->mimetype, 'image/') !== false) ? true : false;
158 * Check if the file got correctly uploaded
160 * @return true if it is a valid upload, false if not
162 function is_uploaded()
164 if (!$this->local && !is_uploaded_file($this->filename))
166 return false;
169 if ($this->local && !file_exists($this->filename))
171 return false;
174 return true;
178 * Remove file
180 function remove()
182 if ($this->file_moved)
184 @unlink($this->destination_file);
189 * Get file extension
191 function get_extension($filename)
193 if (strpos($filename, '.') === false)
195 return '';
198 $filename = explode('.', $filename);
199 return array_pop($filename);
203 * Get mimetype. Utilize mime_content_type if the function exist.
204 * Not used at the moment...
206 function get_mimetype($filename)
208 $mimetype = '';
210 if (function_exists('mime_content_type'))
212 $mimetype = mime_content_type($filename);
215 // Some browsers choke on a mimetype of application/octet-stream
216 if (!$mimetype || $mimetype == 'application/octet-stream')
218 $mimetype = 'application/octetstream';
221 return $mimetype;
225 * Get filesize
227 function get_filesize($filename)
229 return @filesize($filename);
234 * Check the first 256 bytes for forbidden content
236 function check_content($disallowed_content)
238 if (empty($disallowed_content))
240 return true;
243 $fp = @fopen($this->filename, 'rb');
245 if ($fp !== false)
247 $ie_mime_relevant = fread($fp, 256);
248 fclose($fp);
249 foreach ($disallowed_content as $forbidden)
251 if (stripos($ie_mime_relevant, '<' . $forbidden) !== false)
253 return false;
257 return true;
261 * Move file to destination folder
262 * The phpbb_root_path variable will be applied to the destination path
264 * @param string $destination_path Destination path, for example phpbb::$config['avatar_path']
265 * @param bool $overwrite If set to true, an already existing file will be overwritten
266 * @param string $chmod Permission mask for chmodding the file after a successful move. The mode entered here is the octal permission mask.
268 * @access public
270 function move_file($destination, $overwrite = false, $skip_image_check = false, $chmod = false)
272 if (sizeof($this->error))
274 return false;
277 $chmod = ($chmod === false) ? phpbb::CHMOD_READ | phpbb::CHMOD_WRITE : $chmod;
279 // We need to trust the admin in specifying valid upload directories and an attacker not being able to overwrite it...
280 $this->destination_path = PHPBB_ROOT_PATH . $destination;
282 // Check if the destination path exist...
283 if (!file_exists($this->destination_path))
285 @unlink($this->filename);
286 return false;
289 $upload_mode = (@ini_get('open_basedir') || @ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on') ? 'move' : 'copy';
290 $upload_mode = ($this->local) ? 'local' : $upload_mode;
291 $this->destination_file = $this->destination_path . '/' . basename($this->realname);
293 // Check if the file already exist, else there is something wrong...
294 if (file_exists($this->destination_file) && !$overwrite)
296 @unlink($this->filename);
298 else
300 if (file_exists($this->destination_file))
302 @unlink($this->destination_file);
305 switch ($upload_mode)
307 case 'copy':
309 if (!@copy($this->filename, $this->destination_file))
311 if (!@move_uploaded_file($this->filename, $this->destination_file))
313 $this->error[] = sprintf(phpbb::$user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
314 return false;
318 @unlink($this->filename);
320 break;
322 case 'move':
324 if (!@move_uploaded_file($this->filename, $this->destination_file))
326 if (!@copy($this->filename, $this->destination_file))
328 $this->error[] = sprintf(phpbb::$user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
329 return false;
333 @unlink($this->filename);
335 break;
337 case 'local':
339 if (!@copy($this->filename, $this->destination_file))
341 $this->error[] = sprintf(phpbb::$user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
342 return false;
344 @unlink($this->filename);
346 break;
349 phpbb::$system->chmod($this->destination_file, $chmod);
352 // Try to get real filesize from destination folder
353 $this->filesize = (@filesize($this->destination_file)) ? @filesize($this->destination_file) : $this->filesize;
355 if ($this->is_image() && !$skip_image_check)
357 $this->width = $this->height = 0;
359 if (($this->image_info = @getimagesize($this->destination_file)) !== false)
361 $this->width = $this->image_info[0];
362 $this->height = $this->image_info[1];
364 if (!empty($this->image_info['mime']))
366 $this->mimetype = $this->image_info['mime'];
369 // Check image type
370 $types = $this->upload->image_types();
372 if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]]))
374 if (!isset($types[$this->image_info[2]]))
376 $this->error[] = sprintf(phpbb::$user->lang['IMAGE_FILETYPE_INVALID'], $this->image_info[2], $this->mimetype);
378 else
380 $this->error[] = sprintf(phpbb::$user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$this->image_info[2]][0], $this->extension);
384 // Make sure the dimensions match a valid image
385 if (empty($this->width) || empty($this->height))
387 $this->error[] = phpbb::$user->lang['ATTACHED_IMAGE_NOT_IMAGE'];
390 else
392 $this->error[] = phpbb::$user->lang['UNABLE_GET_IMAGE_SIZE'];
396 $this->file_moved = true;
397 $this->additional_checks();
398 unset($this->upload);
400 return true;
404 * Performing additional checks
406 function additional_checks()
408 if (!$this->file_moved)
410 return false;
413 // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form
414 if ($this->upload->max_filesize && ($this->get('filesize') > $this->upload->max_filesize || $this->filesize == 0))
416 $size_lang = ($this->upload->max_filesize >= 1048576) ? phpbb::$user->lang['MIB'] : (($this->upload->max_filesize >= 1024) ? phpbb::$user->lang['KIB'] : phpbb::$user->lang['BYTES'] );
417 $max_filesize = get_formatted_filesize($this->upload->max_filesize, false);
419 $this->error[] = sprintf(phpbb::$user->lang[$this->upload->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
421 return false;
424 if (!$this->upload->valid_dimensions($this))
426 $this->error[] = sprintf(phpbb::$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);
428 return false;
431 return true;
436 * Class for assigning error messages before a real filespec class can be assigned
438 * @package phpBB3
440 class fileerror extends filespec
442 function fileerror($error_msg)
444 $this->error[] = $error_msg;
449 * File upload class
450 * Init class (all parameters optional and able to be set/overwritten separately) - scope is global and valid for all uploads
452 * @package phpBB3
454 class fileupload
456 var $allowed_extensions = array();
457 var $disallowed_content = array();
458 var $max_filesize = 0;
459 var $min_width = 0;
460 var $min_height = 0;
461 var $max_width = 0;
462 var $max_height = 0;
463 var $error_prefix = '';
466 * Init file upload class.
468 * @param string $error_prefix Used error messages will get prefixed by this string
469 * @param array $allowed_extensions Array of allowed extensions, for example array('jpg', 'jpeg', 'gif', 'png')
470 * @param int $max_filesize Maximum filesize
471 * @param int $min_width Minimum image width (only checked for images)
472 * @param int $min_height Minimum image height (only checked for images)
473 * @param int $max_width Maximum image width (only checked for images)
474 * @param int $max_height Maximum image height (only checked for images)
477 function __construct($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)
479 $this->set_allowed_extensions($allowed_extensions);
480 $this->set_max_filesize($max_filesize);
481 $this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height);
482 $this->set_error_prefix($error_prefix);
483 $this->set_disallowed_content($disallowed_content);
487 * Reset vars
489 function reset_vars()
491 $this->max_filesize = 0;
492 $this->min_width = $this->min_height = $this->max_width = $this->max_height = 0;
493 $this->error_prefix = '';
494 $this->allowed_extensions = array();
495 $this->disallowed_content = array();
499 * Set allowed extensions
501 function set_allowed_extensions($allowed_extensions)
503 if ($allowed_extensions !== false && is_array($allowed_extensions))
505 $this->allowed_extensions = $allowed_extensions;
510 * Set allowed dimensions
512 function set_allowed_dimensions($min_width, $min_height, $max_width, $max_height)
514 $this->min_width = (int) $min_width;
515 $this->min_height = (int) $min_height;
516 $this->max_width = (int) $max_width;
517 $this->max_height = (int) $max_height;
521 * Set maximum allowed filesize
523 function set_max_filesize($max_filesize)
525 if ($max_filesize !== false && (int) $max_filesize)
527 $this->max_filesize = (int) $max_filesize;
532 * Set disallowed strings
534 function set_disallowed_content($disallowed_content)
536 if ($disallowed_content !== false && is_array($disallowed_content))
538 $this->disallowed_content = $disallowed_content;
543 * Set error prefix
545 function set_error_prefix($error_prefix)
547 $this->error_prefix = $error_prefix;
551 * Form upload method
552 * Upload file from users harddisk
554 * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified)
555 * @return object $file Object "filespec" is returned, all further operations can be done with this object
556 * @access public
558 function form_upload($form_name)
560 unset($_FILES[$form_name]['local_mode']);
561 $file = new filespec($_FILES[$form_name], $this);
563 if ($file->init_error)
565 $file->error[] = '';
566 return $file;
569 // Error array filled?
570 if (isset($_FILES[$form_name]['error']))
572 $error = $this->assign_internal_error($_FILES[$form_name]['error']);
574 if ($error !== false)
576 $file->error[] = $error;
577 return $file;
581 // Check if empty file got uploaded (not catched by is_uploaded_file)
582 if (isset($_FILES[$form_name]['size']) && $_FILES[$form_name]['size'] == 0)
584 $file->error[] = phpbb::$user->lang[$this->error_prefix . 'EMPTY_FILEUPLOAD'];
585 return $file;
588 // PHP Upload filesize exceeded
589 if ($file->get('filename') == 'none')
591 $max_filesize = @ini_get('upload_max_filesize');
592 $unit = 'MB';
594 if (!empty($max_filesize))
596 $unit = strtolower(substr($max_filesize, -1, 1));
597 $max_filesize = (int) $max_filesize;
599 $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
602 $file->error[] = (empty($max_filesize)) ? phpbb::$user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : phpbb::$user->lang($this->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, phpbb::$user->lang[$unit]);
603 return $file;
606 // Not correctly uploaded
607 if (!$file->is_uploaded())
609 $file->error[] = phpbb::$user->lang[$this->error_prefix . 'NOT_UPLOADED'];
610 return $file;
613 $this->common_checks($file);
615 return $file;
619 * Move file from another location to phpBB
621 function local_upload($source_file, $filedata = false)
623 $form_name = 'local';
625 $_FILES[$form_name]['local_mode'] = true;
626 $_FILES[$form_name]['tmp_name'] = $source_file;
628 if ($filedata === false)
630 $_FILES[$form_name]['name'] = basename($source_file);
631 $_FILES[$form_name]['size'] = 0;
632 $mimetype = '';
634 if (function_exists('mime_content_type'))
636 $mimetype = mime_content_type($source_file);
639 // Some browsers choke on a mimetype of application/octet-stream
640 if (!$mimetype || $mimetype == 'application/octet-stream')
642 $mimetype = 'application/octetstream';
645 $_FILES[$form_name]['type'] = $mimetype;
647 else
649 $_FILES[$form_name]['name'] = $filedata['realname'];
650 $_FILES[$form_name]['size'] = $filedata['size'];
651 $_FILES[$form_name]['type'] = $filedata['type'];
654 $file = new filespec($_FILES[$form_name], $this);
656 if ($file->init_error)
658 $file->error[] = '';
659 return $file;
662 if (isset($_FILES[$form_name]['error']))
664 $error = $this->assign_internal_error($_FILES[$form_name]['error']);
666 if ($error !== false)
668 $file->error[] = $error;
669 return $file;
673 // PHP Upload filesize exceeded
674 if ($file->get('filename') == 'none')
676 $max_filesize = @ini_get('upload_max_filesize');
677 $unit = 'MB';
679 if (!empty($max_filesize))
681 $unit = strtolower(substr($max_filesize, -1, 1));
682 $max_filesize = (int) $max_filesize;
684 $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
687 $file->error[] = (empty($max_filesize)) ? phpbb::$user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : phpbb::$user->lang($this->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, phpbb::$user->lang[$unit]);
688 return $file;
691 // Not correctly uploaded
692 if (!$file->is_uploaded())
694 $file->error[] = phpbb::$user->lang[$this->error_prefix . 'NOT_UPLOADED'];
695 return $file;
698 $this->common_checks($file);
700 return $file;
704 * Remote upload method
705 * Uploads file from given url
707 * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
708 * @return object $file Object "filespec" is returned, all further operations can be done with this object
709 * @access public
711 function remote_upload($upload_url)
713 $upload_ary = array();
714 $upload_ary['local_mode'] = true;
716 if (!preg_match('#^(https?://).*?\.(' . implode('|', $this->allowed_extensions) . ')$#i', $upload_url, $match))
718 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'URL_INVALID']);
719 return $file;
722 if (empty($match[2]))
724 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'URL_INVALID']);
725 return $file;
728 $url = parse_url($upload_url);
730 $host = $url['host'];
731 $path = $url['path'];
732 $port = (!empty($url['port'])) ? (int) $url['port'] : 80;
734 $upload_ary['type'] = 'application/octet-stream';
736 $url['path'] = explode('.', $url['path']);
737 $ext = array_pop($url['path']);
739 $url['path'] = implode('', $url['path']);
740 $upload_ary['name'] = basename($url['path']) . (($ext) ? '.' . $ext : '');
741 $filename = $url['path'];
742 $filesize = 0;
744 $errno = 0;
745 $errstr = '';
747 if (!($fsock = @fsockopen($host, $port, $errno, $errstr)))
749 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'NOT_UPLOADED']);
750 return $file;
753 // Make sure $path not beginning with /
754 if (strpos($path, '/') === 0)
756 $path = substr($path, 1);
759 fputs($fsock, 'GET /' . $path . " HTTP/1.1\r\n");
760 fputs($fsock, "HOST: " . $host . "\r\n");
761 fputs($fsock, "Connection: close\r\n\r\n");
763 $get_info = false;
764 $data = '';
765 while (!@feof($fsock))
767 if ($get_info)
769 $data .= @fread($fsock, 1024);
771 else
773 $line = @fgets($fsock, 1024);
775 if ($line == "\r\n")
777 $get_info = true;
779 else
781 if (stripos($line, 'content-type: ') !== false)
783 $upload_ary['type'] = rtrim(str_replace('content-type: ', '', strtolower($line)));
785 else if (stripos($line, '404 not found') !== false)
787 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'URL_NOT_FOUND']);
788 return $file;
793 @fclose($fsock);
795 if (empty($data))
797 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'EMPTY_REMOTE_DATA']);
798 return $file;
801 $tmp_path = (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') ? false : PHPBB_ROOT_PATH . 'cache';
802 $filename = tempnam($tmp_path, unique_id() . '-');
804 if (!($fp = @fopen($filename, 'wb')))
806 $file = new fileerror(phpbb::$user->lang[$this->error_prefix . 'NOT_UPLOADED']);
807 return $file;
810 $upload_ary['size'] = fwrite($fp, $data);
811 fclose($fp);
812 unset($data);
814 $upload_ary['tmp_name'] = $filename;
816 $file = new filespec($upload_ary, $this);
817 $this->common_checks($file);
819 return $file;
823 * Assign internal error
824 * @access private
826 function assign_internal_error($errorcode)
828 switch ($errorcode)
830 case 1:
831 $max_filesize = @ini_get('upload_max_filesize');
832 $unit = 'MB';
834 if (!empty($max_filesize))
836 $unit = strtolower(substr($max_filesize, -1, 1));
837 $max_filesize = (int) $max_filesize;
839 $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
842 $error = (empty($max_filesize)) ? phpbb::$user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : phpbb::$user->lang($this->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, phpbb::$user->lang[$unit]);
843 break;
845 case 2:
846 $size_lang = ($this->max_filesize >= 1048576) ? phpbb::$user->lang['MIB'] : (($this->max_filesize >= 1024) ? phpbb::$user->lang['KIB'] : phpbb::$user->lang['BYTES']);
847 $max_filesize = get_formatted_filesize($this->max_filesize, false);
849 $error = sprintf(phpbb::$user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
850 break;
852 case 3:
853 $error = phpbb::$user->lang[$this->error_prefix . 'PARTIAL_UPLOAD'];
854 break;
856 case 4:
857 $error = phpbb::$user->lang[$this->error_prefix . 'NOT_UPLOADED'];
858 break;
860 case 6:
861 $error = 'Temporary folder could not be found. Please check your PHP installation.';
862 break;
864 default:
865 $error = false;
866 break;
869 return $error;
873 * Perform common checks
875 function common_checks(&$file)
877 // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form
878 if ($this->max_filesize && ($file->get('filesize') > $this->max_filesize || $file->get('filesize') == 0))
880 $size_lang = ($this->max_filesize >= 1048576) ? phpbb::$user->lang['MIB'] : (($this->max_filesize >= 1024) ? phpbb::$user->lang['KIB'] : phpbb::$user->lang['BYTES']);
881 $max_filesize = get_formatted_filesize($this->max_filesize, false);
883 $file->error[] = sprintf(phpbb::$user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
886 // check Filename
887 if (preg_match("#[\\/:*?\"<>|]#i", $file->get('realname')))
889 $file->error[] = sprintf(phpbb::$user->lang[$this->error_prefix . 'INVALID_FILENAME'], $file->get('realname'));
892 // Invalid Extension
893 if (!$this->valid_extension($file))
895 $file->error[] = sprintf(phpbb::$user->lang[$this->error_prefix . 'DISALLOWED_EXTENSION'], $file->get('extension'));
898 // MIME Sniffing
899 if (!$this->valid_content($file))
901 $file->error[] = sprintf(phpbb::$user->lang[$this->error_prefix . 'DISALLOWED_CONTENT']);
906 * Check for allowed extension
908 function valid_extension(&$file)
910 return (in_array($file->get('extension'), $this->allowed_extensions)) ? true : false;
914 * Check for allowed dimension
916 function valid_dimensions(&$file)
918 if (!$this->max_width && !$this->max_height && !$this->min_width && !$this->min_height)
920 return true;
923 if (($file->get('width') > $this->max_width && $this->max_width) ||
924 ($file->get('height') > $this->max_height && $this->max_height) ||
925 ($file->get('width') < $this->min_width && $this->min_width) ||
926 ($file->get('height') < $this->min_height && $this->min_height))
928 return false;
931 return true;
935 * Check if form upload is valid
937 function is_valid($form_name)
939 return (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none') ? true : false;
944 * Check for allowed extension
946 function valid_content(&$file)
948 return ($file->check_content($this->disallowed_content));
952 * Return image type/extension mapping
954 function image_types()
956 return array(
957 1 => array('gif'),
958 2 => array('jpg', 'jpeg'),
959 3 => array('png'),
960 4 => array('swf'),
961 5 => array('psd'),
962 6 => array('bmp'),
963 7 => array('tif', 'tiff'),
964 8 => array('tif', 'tiff'),
965 9 => array('jpg', 'jpeg'),
966 10 => array('jpg', 'jpeg'),
967 11 => array('jpg', 'jpeg'),
968 12 => array('jpg', 'jpeg'),
969 13 => array('swc'),
970 14 => array('iff'),
971 15 => array('wbmp'),
972 16 => array('xbm'),