PHP Class CI_Upload, TastyIgniter

Author: ExpressionEngine Dev Team
显示文件 Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$allowed_types string Allowed file types
$client_name boolean Filename sent by the client
$detect_mime boolean MIME detection flag
$encrypt_name boolean Obfuscate filename flag
$error_msg array Error messages list
$file_ext string Filename extension
$file_ext_tolower string Force filename extension to lowercase
$file_name string Filename
$file_size integer File size
$file_temp string Temporary filename
$file_type string File type
$image_height integer Image height
$image_size_str string Image size string
$image_type string Image type
$image_width integer Image width
$is_image boolean Is image flag
$max_filename integer Maximum filename length
$max_filename_increment integer Maximum duplicate filename increment ID
$max_height integer Maximum image height
$max_size integer Maximum file size
$max_width integer Maximum image width
$min_height integer Minimum image height
$min_width integer Minimum image width
$mod_mime_fix boolean Apache mod_mime fix flag
$orig_name string Original filename
$overwrite boolean Overwrite flag
$remove_spaces boolean Remove spaces flag
$temp_prefix string Temporary filename prefix
$upload_path string Upload path
$xss_clean boolean XSS filter flag

Protected Properties

Property Type Description
$_CI object CI Singleton
$_file_name_override string Filename override
$_mimes array MIME types list

Public Methods

Method Description
__construct ( $config = [] ) : void Constructor
data ( string $index = NULL ) : mixed Finalized Data Array
display_errors ( string $open = '<p>', string $close = '</p>' ) : string Display the error message
do_upload ( string $field = 'userfile' ) : boolean Perform the file upload
do_xss_clean ( ) : string Runs the file through the XSS clean function
get_extension ( string $filename ) : string Extract the file extension
initialize ( array $config = [], boolean $reset = TRUE ) : CI_Upload Initialize preferences
is_allowed_dimensions ( ) : boolean Verify that the image is within the allowed width/height
is_allowed_filesize ( ) : boolean Verify that the file is within the allowed size
is_allowed_filetype ( boolean $ignore_mime = FALSE ) : boolean Verify that the filetype is allowed
is_image ( ) : boolean Validate the image
limit_filename_length ( string $filename, integer $length ) : string Limit the File Name Length
set_allowed_types ( mixed $types ) : CI_Upload Set Allowed File Types
set_error ( string $msg, $log_level = 'error' ) : CI_Upload Set an error message
set_filename ( string $path, string $filename ) : string Set the file name
set_image_properties ( string $path = '' ) : CI_Upload Set Image Properties
set_max_filename ( integer $n ) : CI_Upload Set Maximum File Name Length
set_max_filesize ( integer $n ) : CI_Upload Set Maximum File Size
set_max_height ( integer $n ) : CI_Upload Set Maximum Image Height
set_max_width ( integer $n ) : CI_Upload Set Maximum Image Width
set_min_height ( integer $n ) : CI_Upload Set minimum image height
set_min_width ( integer $n ) : CI_Upload Set minimum image width
set_upload_path ( string $path ) : CI_Upload Set Upload Path
set_xss_clean ( boolean $flag = FALSE ) : CI_Upload Set XSS Clean
validate_upload_path ( ) : boolean Validate Upload Path

Protected Methods

Method Description
_file_mime_type ( array $file ) : void File MIME type
_prep_filename ( string $filename ) : string Prep Filename
set_max_size ( integer $n ) : CI_Upload Set Maximum File Size

Method Details

__construct() public method

Constructor
public __construct ( $config = [] ) : void
return void

_file_mime_type() protected method

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

_prep_filename() protected method

Prevents possible script execution from Apache's handling of files' multiple extensions.
protected _prep_filename ( string $filename ) : string
$filename string
return string

data() public method

Returns an associative array containing all of the information related to the upload, allowing the developer easy access in one array.
public data ( string $index = NULL ) : mixed
$index string
return mixed

display_errors() public method

Display the error message
public display_errors ( string $open = '<p>', string $close = '</p>' ) : string
$open string
$close string
return string

do_upload() public method

Perform the file upload
public do_upload ( string $field = 'userfile' ) : boolean
$field string
return boolean

do_xss_clean() public method

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 do_xss_clean ( ) : string
return string

get_extension() public method

Extract the file extension
public get_extension ( string $filename ) : string
$filename string
return string

initialize() public method

Initialize preferences
public initialize ( array $config = [], boolean $reset = TRUE ) : CI_Upload
$config array
$reset boolean
return CI_Upload

is_allowed_dimensions() public method

Verify that the image is within the allowed width/height
public is_allowed_dimensions ( ) : boolean
return boolean

is_allowed_filesize() public method

Verify that the file is within the allowed size
public is_allowed_filesize ( ) : boolean
return boolean

is_allowed_filetype() public method

Verify that the filetype is allowed
public is_allowed_filetype ( boolean $ignore_mime = FALSE ) : boolean
$ignore_mime boolean
return boolean

is_image() public method

Validate the image
public is_image ( ) : boolean
return boolean

limit_filename_length() public method

Limit the File Name Length
public limit_filename_length ( string $filename, integer $length ) : string
$filename string
$length integer
return string

set_allowed_types() public method

Set Allowed File Types
public set_allowed_types ( mixed $types ) : CI_Upload
$types mixed
return CI_Upload

set_error() public method

Set an error message
public set_error ( string $msg, $log_level = 'error' ) : CI_Upload
$msg string
return CI_Upload

set_filename() public method

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.
public set_filename ( string $path, string $filename ) : string
$path string
$filename string
return string

set_image_properties() public method

Uses GD to determine the width/height/type of image
public set_image_properties ( string $path = '' ) : CI_Upload
$path string
return CI_Upload

set_max_filename() public method

Set Maximum File Name Length
public set_max_filename ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_max_filesize() public method

Set Maximum File Size
public set_max_filesize ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_max_height() public method

Set Maximum Image Height
public set_max_height ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_max_size() protected method

An internal alias to set_max_filesize() to help with configuration as initialize() will look for a set_() method ...
protected set_max_size ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_max_width() public method

Set Maximum Image Width
public set_max_width ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_min_height() public method

Set minimum image height
public set_min_height ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_min_width() public method

Set minimum image width
public set_min_width ( integer $n ) : CI_Upload
$n integer
return CI_Upload

set_upload_path() public method

Set Upload Path
public set_upload_path ( string $path ) : CI_Upload
$path string
return CI_Upload

set_xss_clean() public method

Enables the XSS flag so that the file that was uploaded will be run through the XSS filter.
public set_xss_clean ( boolean $flag = FALSE ) : CI_Upload
$flag boolean
return CI_Upload

validate_upload_path() public method

Verifies that it is a valid upload path with proper permissions.
public validate_upload_path ( ) : boolean
return boolean

Property Details

$_CI protected_oe property

CI Singleton
protected object $_CI
return object

$_file_name_override protected_oe property

Filename override
protected string $_file_name_override
return string

$_mimes protected_oe property

MIME types list
protected array $_mimes
return array

$allowed_types public_oe property

Allowed file types
public string $allowed_types
return string

$client_name public_oe property

Filename sent by the client
public bool $client_name
return boolean

$detect_mime public_oe property

MIME detection flag
public bool $detect_mime
return boolean

$encrypt_name public_oe property

Obfuscate filename flag
public bool $encrypt_name
return boolean

$error_msg public_oe property

Error messages list
public array $error_msg
return array

$file_ext public_oe property

Filename extension
public string $file_ext
return string

$file_ext_tolower public_oe property

Force filename extension to lowercase
public string $file_ext_tolower
return string

$file_name public_oe property

Filename
public string $file_name
return string

$file_size public_oe property

File size
public int $file_size
return integer

$file_temp public_oe property

Temporary filename
public string $file_temp
return string

$file_type public_oe property

File type
public string $file_type
return string

$image_height public_oe property

Image height
public int $image_height
return integer

$image_size_str public_oe property

Image size string
public string $image_size_str
return string

$image_type public_oe property

Image type
public string $image_type
return string

$image_width public_oe property

Image width
public int $image_width
return integer

$is_image public_oe property

Is image flag
public bool $is_image
return boolean

$max_filename public_oe property

Maximum filename length
public int $max_filename
return integer

$max_filename_increment public_oe property

Maximum duplicate filename increment ID
public int $max_filename_increment
return integer

$max_height public_oe property

Maximum image height
public int $max_height
return integer

$max_size public_oe property

Maximum file size
public int $max_size
return integer

$max_width public_oe property

Maximum image width
public int $max_width
return integer

$min_height public_oe property

Minimum image height
public int $min_height
return integer

$min_width public_oe property

Minimum image width
public int $min_width
return integer

$mod_mime_fix public_oe property

Apache mod_mime fix flag
public bool $mod_mime_fix
return boolean

$orig_name public_oe property

Original filename
public string $orig_name
return string

$overwrite public_oe property

Overwrite flag
public bool $overwrite
return boolean

$remove_spaces public_oe property

Remove spaces flag
public bool $remove_spaces
return boolean

$temp_prefix public_oe property

Temporary filename prefix
public string $temp_prefix
return string

$upload_path public_oe property

Upload path
public string $upload_path
return string

$xss_clean public_oe property

XSS filter flag
public bool $xss_clean
return boolean