Skip to content

CI_Upload

Mathieu Nayrolles edited this page Jan 20, 2016 · 1 revision

CI_Upload

File Uploading Class

  • Class name: CI_Upload
  • Namespace:

Properties

$max_size

public integer $max_size

Maximum file size

  • Visibility: public

$max_width

public integer $max_width

Maximum image width

  • Visibility: public

$max_height

public integer $max_height

Maximum image height

  • Visibility: public

$min_width

public integer $min_width

Minimum image width

  • Visibility: public

$min_height

public integer $min_height

Minimum image height

  • Visibility: public

$max_filename

public integer $max_filename

Maximum filename length

  • Visibility: public

$max_filename_increment

public integer $max_filename_increment = 100

Maximum duplicate filename increment ID

  • Visibility: public

$allowed_types

public string $allowed_types = ''

Allowed file types

  • Visibility: public

$file_temp

public string $file_temp = ''

Temporary filename

  • Visibility: public

$file_name

public string $file_name = ''

Filename

  • Visibility: public

$orig_name

public string $orig_name = ''

Original filename

  • Visibility: public

$file_type

public string $file_type = ''

File type

  • Visibility: public

$file_size

public integer $file_size = NULL

File size

  • Visibility: public

$file_ext

public string $file_ext = ''

Filename extension

  • Visibility: public

$file_ext_tolower

public string $file_ext_tolower = FALSE

Force filename extension to lowercase

  • Visibility: public

$upload_path

public string $upload_path = ''

Upload path

  • Visibility: public

$overwrite

public boolean $overwrite = FALSE

Overwrite flag

  • Visibility: public

$encrypt_name

public boolean $encrypt_name = FALSE

Obfuscate filename flag

  • Visibility: public

$is_image

public boolean $is_image = FALSE

Is image flag

  • Visibility: public

$image_width

public integer $image_width = NULL

Image width

  • Visibility: public

$image_height

public integer $image_height = NULL

Image height

  • Visibility: public

$image_type

public string $image_type = ''

Image type

  • Visibility: public

$image_size_str

public string $image_size_str = ''

Image size string

  • Visibility: public

$error_msg

public array $error_msg = array()

Error messages list

  • Visibility: public

$remove_spaces

public boolean $remove_spaces = TRUE

Remove spaces flag

  • Visibility: public

$detect_mime

public boolean $detect_mime = TRUE

MIME detection flag

  • Visibility: public

$xss_clean

public boolean $xss_clean = FALSE

XSS filter flag

  • Visibility: public

$mod_mime_fix

public boolean $mod_mime_fix = TRUE

Apache mod_mime fix flag

  • Visibility: public

$temp_prefix

public string $temp_prefix = 'temp_file_'

Temporary filename prefix

  • Visibility: public

$client_name

public boolean $client_name = ''

Filename sent by the client

  • Visibility: public

$_file_name_override

protected string $_file_name_override = ''

Filename override

  • Visibility: protected

$_mimes

protected array $_mimes = array()

MIME types list

  • Visibility: protected

$_CI

protected object $_CI

CI Singleton

  • Visibility: protected

Methods

__construct

void CI_Upload::__construct($config)

Constructor

  • Visibility: public

Arguments

  • $config mixed

initialize

\CI_Upload CI_Upload::initialize(array $config, boolean $reset)

Initialize preferences

  • Visibility: public

Arguments

  • $config array
  • $reset boolean

do_upload

boolean CI_Upload::do_upload(string $field)

Perform the file upload

  • Visibility: public

Arguments

  • $field string

data

mixed CI_Upload::data(string $index)

Finalized Data Array

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

  • Visibility: public

Arguments

  • $index string

set_upload_path

\CI_Upload CI_Upload::set_upload_path(string $path)

Set Upload Path

  • Visibility: public

Arguments

  • $path string

set_filename

string CI_Upload::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.

  • Visibility: public

Arguments

  • $path string
  • $filename string

set_max_filesize

\CI_Upload CI_Upload::set_max_filesize(integer $n)

Set Maximum File Size

  • Visibility: public

Arguments

  • $n integer

set_max_size

\CI_Upload CI_Upload::set_max_size(integer $n)

Set Maximum File Size

An internal alias to set_max_filesize() to help with configuration as initialize() will look for a set_<property_name>() method ...

  • Visibility: protected

Arguments

  • $n integer

set_max_filename

\CI_Upload CI_Upload::set_max_filename(integer $n)

Set Maximum File Name Length

  • Visibility: public

Arguments

  • $n integer

set_max_width

\CI_Upload CI_Upload::set_max_width(integer $n)

Set Maximum Image Width

  • Visibility: public

Arguments

  • $n integer

set_max_height

\CI_Upload CI_Upload::set_max_height(integer $n)

Set Maximum Image Height

  • Visibility: public

Arguments

  • $n integer

set_min_width

\CI_Upload CI_Upload::set_min_width(integer $n)

Set minimum image width

  • Visibility: public

Arguments

  • $n integer

set_min_height

\CI_Upload CI_Upload::set_min_height(integer $n)

Set minimum image height

  • Visibility: public

Arguments

  • $n integer

set_allowed_types

\CI_Upload CI_Upload::set_allowed_types(mixed $types)

Set Allowed File Types

  • Visibility: public

Arguments

  • $types mixed

set_image_properties

\CI_Upload CI_Upload::set_image_properties(string $path)

Set Image Properties

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

  • Visibility: public

Arguments

  • $path string

set_xss_clean

\CI_Upload CI_Upload::set_xss_clean(boolean $flag)

Set XSS Clean

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

  • Visibility: public

Arguments

  • $flag boolean

is_image

boolean CI_Upload::is_image()

Validate the image

  • Visibility: public

is_allowed_filetype

boolean CI_Upload::is_allowed_filetype(boolean $ignore_mime)

Verify that the filetype is allowed

  • Visibility: public

Arguments

  • $ignore_mime boolean

is_allowed_filesize

boolean CI_Upload::is_allowed_filesize()

Verify that the file is within the allowed size

  • Visibility: public

is_allowed_dimensions

boolean CI_Upload::is_allowed_dimensions()

Verify that the image is within the allowed width/height

  • Visibility: public

validate_upload_path

boolean CI_Upload::validate_upload_path()

Validate Upload Path

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

  • Visibility: public

get_extension

string CI_Upload::get_extension(string $filename)

Extract the file extension

  • Visibility: public

Arguments

  • $filename string

limit_filename_length

string CI_Upload::limit_filename_length(string $filename, integer $length)

Limit the File Name Length

  • Visibility: public

Arguments

  • $filename string
  • $length integer

do_xss_clean

string CI_Upload::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.

  • Visibility: public

set_error

\CI_Upload CI_Upload::set_error(string $msg, $log_level)

Set an error message

  • Visibility: public

Arguments

  • $msg string
  • $log_level mixed

display_errors

string CI_Upload::display_errors(string $open, string $close)

Display the error message

  • Visibility: public

Arguments

  • $open string
  • $close string

_prep_filename

string CI_Upload::_prep_filename(string $filename)

Prep Filename

Prevents possible script execution from Apache's handling of files' multiple extensions.

  • Visibility: protected

Arguments

  • $filename string

_file_mime_type

void CI_Upload::_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]

  • Visibility: protected

Arguments

  • $file array
Clone this wiki locally