Constants

NOFILE

NOFILE

FILESIZE

FILESIZE

FILETYPE

FILETYPE

FILEEXISTS

FILEEXISTS

BADDESTDIR

BADDESTDIR

BADPERMS

BADPERMS

MOVEFAILED

MOVEFAILED

UPLOADFAILED

UPLOADFAILED

PREPROCESSING_FAILED

PREPROCESSING_FAILED

Methods

set_preview()

set_preview(bool $flag)

Set a flag indicating that a preview (slightly larger than a thumbnail) image should be generated from an uploaded image.

Parameters

bool $flag

set_preview_size()

set_preview_size(int $size)

Set the size (in pixels) of the preview image.

This is only applicable if preview is enabled.

Parameters

int $size

set_watermark()

set_watermark(bool $flag)

Set a flag indicating that an uploaded image should be watermarked.

Parameters

bool $flag

set_thumbnail()

set_thumbnail(bool $flag)

Set a flag indicating that a thumbnail should be generated from an uploaded image.

Parameters

bool $flag

set_thumbnail_size()

set_thumbnail_size(int $size)

Set the size (in pixels) of the generated thumbnails.

Parameters

int $size

set_delete_orig()

set_delete_orig(bool $flag)

Set a flag to indicate that the original file should be deleted after processing.

Parameters

bool $flag

is_accepted_imagefile()

is_accepted_imagefile(string $filename) : bool

Test wether the filename specified is a file acceptable for processing.

Parameters

string $filename

Returns

bool

get_accepted_imagetypes()

get_accepted_imagetypes() : string[]

Return a list of the file extensions that will be accepted for processing on upload.

Returns

string[]

set_accepted_imagetypes()

set_accepted_imagetypes(string|string[] $imagetypes)

Set the list of file extensions that will be accepted for processing on upload.

Parameters

string|string[] $imagetypes

Either an array or a comma delimited list of file extensions.

handle_upload()

handle_upload(string $name, string $destfilename, string $subfield) : bool

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

bool —

True on success, false on error.

__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) : bool

Test if the specified filename is among the accepted filetypes

Parameters

string $filename

Returns

bool

set_max_filesize()

set_max_filesize(int $size)

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

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

Parameters

int $size

set_allow_overwrite()

set_allow_overwrite(bool $flag)

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

Parameters

bool $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) : bool

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

bool

check_upload()

check_upload(string $name, string $subfield, bool $checkdir) : bool

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

bool $checkdir

Test if the destination directory exists, and is writable.

Returns

bool —

True on success, false on error.

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

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