Class CI_Upload - echiong/testRepo GitHub Wiki

##Class CI_Upload

File Uploading Class

Package: [[CodeIgniter<a href="Package CodeIgniter.Libraries.md">Libraries]]
Category: Uploads
Author: ExpressionEngine Dev Team
Link: http://codeigniter.com/user_guide/libraries/file_uploading.html
Located at system/libraries/Upload.php

##Methods summary


public __construct ( mixed $props = array() )

Constructor


public initialize ( array $config = array() )

Initialize preferences

Parameters

$config array


public boolean do_upload ( mixed $field = 'userfile' )

Perform the file upload

Returns boolean


public array data ( )

Finalized Data Array

Returns an associative array containing all of the information related to the upload, allowing the developer easy access in one array.

Returns array


public set_upload_path ( string $path )

Set Upload Path

Parameters

$path string


public string set_filename ( string $path, string $filename )

Set the file name

This function takes a filename/path as input and looks for the existence of a file with the same name. If found, it will append a number to the end of the filename to avoid overwriting a pre-existing file.

Parameters

$path string

$filename string

Returns string


public set_max_filesize ( integer $n )

Set Maximum File Size

Parameters

$n integer


public set_max_filename ( integer $n )

Set Maximum File Name Length

Parameters

$n integer


public set_max_width ( integer $n )

Set Maximum Image Width

Parameters

$n integer


public set_max_height ( integer $n )

Set Maximum Image Height

Parameters

$n integer


public set_allowed_types ( string $types )

Set Allowed File Types

Parameters

$types string


public set_image_properties ( string $path = '' )

Set Image Properties

Uses GD to determine the width/height/type of image

Parameters

$path string


public set_xss_clean ( boolean $flag = FALSE )

Set XSS Clean

Enables the XSS flag so that the file that was uploaded will be run through the XSS filter.

Parameters

$flag boolean


public boolean is_image ( )

Validate the image

Returns boolean


public boolean is_allowed_filetype ( mixed $ignore_mime = FALSE )

Verify that the filetype is allowed

Returns boolean


public boolean is_allowed_filesize ( )

Verify that the file is within the allowed size

Returns boolean


public boolean is_allowed_dimensions ( )

Verify that the image is within the allowed width/height

Returns boolean


public boolean validate_upload_path ( )

Validate Upload Path

Verifies that it is a valid upload path with proper permissions.

Returns boolean


public string get_extension ( string $filename )

Extract the file extension

Parameters

$filename string

Returns string


public string clean_file_name ( string $filename )

Clean the file name for security

Parameters

$filename string

Returns string


public string limit_filename_length ( string $filename, mixed $length )

Limit the File Name Length

Parameters

$filename string

$length

Returns string


public do_xss_clean ( )

Runs the file through the XSS clean function

This prevents people from embedding malicious code in their files. I'm not sure that it won't negatively affect certain files in unexpected ways, but so far I haven't found that it causes trouble.


public set_error ( string $msg )

Set an error message

Parameters

$msg string


public string display_errors ( string $open = '<p>', string $close = '</p>' )

Display the error message

Parameters

$open string

$close string

Returns string


public string mimes_types ( string $mime )

List of Mime Types

This is a list of mime types. We use it to validate the "allowed types" set by the developer

Parameters

$mime string

Returns string


protected string _prep_filename ( string $filename )

Prep Filename

Prevents possible script execution from Apache's handling of files multiple extensions http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext

Parameters

$filename string

Returns string


protected _file_mime_type ( array $file )

File MIME type

Detects the (actual) MIME type of the uploaded file, if possible. The input array is expected to be $_FILES[$field]

Parameters

$file array

<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="max_size" id="$max_size">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$max_size

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="max_width" id="$max_width">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$max_width

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="max_height" id="$max_height">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$max_height

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="max_filename" id="$max_filename">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$max_filename

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="allowed_types" id="$allowed_types">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$allowed_types

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_temp" id="$file_temp">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$file_temp

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_name" id="$file_name">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$file_name

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="orig_name" id="$orig_name">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$orig_name

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_type" id="$file_type">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$file_type

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_size" id="$file_size">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$file_size

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_ext" id="$file_ext">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$file_ext

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="upload_path" id="$upload_path">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$upload_path

""
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="overwrite" id="$overwrite">
	<td class="attributes"><code>
		public  
		boolean
	</code></td>

	<td class="name">

$overwrite

FALSE
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="encrypt_name" id="$encrypt_name">
	<td class="attributes"><code>
		public  
		boolean
	</code></td>

	<td class="name">

$encrypt_name

FALSE
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="is_image" id="$is_image">
	<td class="attributes"><code>
		public  
		boolean
	</code></td>

	<td class="name">

$is_image

FALSE
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="image_width" id="$image_width">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$image_width

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="image_height" id="$image_height">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$image_height

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="image_type" id="$image_type">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$image_type

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="image_size_str" id="$image_size_str">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$image_size_str

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="error_msg" id="$error_msg">
	<td class="attributes"><code>
		public  
		array
	</code></td>

	<td class="name">

$error_msg

array()
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="mimes" id="$mimes">
	<td class="attributes"><code>
		public  
		array
	</code></td>

	<td class="name">

$mimes

array()
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="remove_spaces" id="$remove_spaces">
	<td class="attributes"><code>
		public  
		boolean
	</code></td>

	<td class="name">

$remove_spaces

TRUE
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="xss_clean" id="$xss_clean">
	<td class="attributes"><code>
		public  
		boolean
	</code></td>

	<td class="name">

$xss_clean

FALSE
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="temp_prefix" id="$temp_prefix">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$temp_prefix

"temp_file_"
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="client_name" id="$client_name">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$client_name

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="_file_name_override" id="$_file_name_override">
	<td class="attributes"><code>
		protected  
		string
	</code></td>

	<td class="name">

$_file_name_override

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
</table>
⚠️ **GitHub.com Fallback** ⚠️