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