Constants

NOFILE

NOFILE

FILESIZE

FILESIZE

FILETYPE

FILETYPE

FILEEXISTS

FILEEXISTS

BADDESTDIR

BADDESTDIR

BADPERMS

BADPERMS

MOVEFAILED

MOVEFAILED

UPLOADFAILED

UPLOADFAILED

PREPROCESSING_FAILED

PREPROCESSING_FAILED

Methods

__construct()

__construct(string  $prefix = '', string  $destdir = '') 

Constructor

Parameters

string $prefix

A common array key prefix for all files to be handled by this object.

string $destdir

The full path to the destination directory.

set_preprocessor()

set_preprocessor(callable  $func) 

Set a preprocessor object

Parameters

callable $func

get_accepted_filetypes()

get_accepted_filetypes() 

Return the list of accepted file extensions

set_accepted_filetypes()

set_accepted_filetypes(mixed  $filetypes) 

Set the list of accepted file extensions

Parameters

mixed $filetypes

Accepts an array of strings, or a comma separated list of strings.

is_accepted_file()

is_accepted_file(string  $filename) : boolean

Test if the specified filename is among the accepted filetypes

Parameters

string $filename

Returns

boolean

set_max_filesize()

set_max_filesize(integer  $size) 

Set the maximum file size for uploaded files (in kilobytes).

This method has no effect on the php.ini settings.

Parameters

integer $size

set_allow_overwrite()

set_allow_overwrite(boolean  $flag = true) 

Set a flag that indicates wether overwriting existing files is permitted.

Parameters

boolean $flag

get_error()

get_error() : string

Get any error code returned after handling the upload.

See the error codes contained in this string.

Returns

string

get_errormsg()

get_errormsg() : string

Return a human readable message pertaining to any error code returned after handling the upload.

Returns

string

reset_errors()

reset_errors() 

Reset any errors

get_dest_dir()

get_dest_dir() : string

Return the destination directory for uploaded files

Returns

string

set_dest_dir()

set_dest_dir(string  $dir) 

Set the destination directory for uploaded files

Parameters

string $dir

The destination directory

get_dest_filename()

get_dest_filename() : string

Get the optional destination filename. If any has been specified.

Returns

string

get_orig_filename()

get_orig_filename() 

Get the original filename.

This method is only useful after handle_upload has been called.

check_upload_attempted()

check_upload_attempted(string  $name, string  $subfield = null) : boolean

Check if a file has been uploaded with the specified field name.

If specified in the constructor a prefix will be prepended to this name for comparison. This method will not set any of the error members in the object.

Parameters

string $name

The field name

string $subfield

Assume that the prefix+field name represent an array

Returns

boolean

get_uploaded_filename()

get_uploaded_filename(string  $field_name, string  $subfield = null) 

Get the name of an uploaded file before processing

Parameters

string $field_name

The input field name

string $subfield

An optional subfield name

check_upload()

check_upload(string  $name, string  $subfield = null, boolean  $checkdir = TRUE) : boolean

Check if a file has been uploaded to the specified name, and if it is valid.

If specified in the constructor a prefix will be prepended to this name for comparison. This method will set internal error strings and numbers on failure.

Parameters

string $name

The upload key name

string $subfield

Assume that the prefix+field name represent an array

boolean $checkdir

Test if the destination directory exists, and is writable.

Returns

boolean —

True on success, false on error.

handle_upload()

handle_upload(string  $name, string  $destfilename = '', string  $subfield = null) : boolean

Handle preprocessing an uploaded file, test for errors and move the file to its destination location.

Parameters

string $name

The upload key name

string $destfilename

An optional destination filename.

string $subfield

Assume that the prefix+field name represent an array

Returns

boolean —

True on success, false on error.

set_errno()

set_errno(string  $val) 

Set the current error code See error codes defined above.

Parameters

string $val

set_error()

set_error(string  $val) 

Set a human readable error message.

Parameters

string $val

get_new_filename()

get_new_filename(string  $input_name) : string

Get an adjusted upload filename, using the destname if provided.

Note: extension will be preserved in output filename.

Parameters

string $input_name

The input filename

Returns

string

get_file_record()

get_file_record(string  $field_name, string  $subfield = null) : array|null

Given a field name, and a subfield.

. get the aggregated record from $_FILES so that the upload can be processed.

In the event of a problem this method sets the errno variable for error handling.

Parameters

string $field_name

The input field name

string $subfield

The name of any subfield.

Returns

array|null

preprocess_upload()

preprocess_upload(array  $fileinfo) : string

Preprocess the uploaded file.

If a preprocessor has been passed into this object, this method will preprocess the file

Parameters

array $fileinfo

The file info record (from the $_FILES array) for the file to preprocess.

Returns

string —

The filename of the pre-processed file on success. Otherwise, FALSE