AnewtFormControlFileUpload class

Extended file upload form control with some automatic file and error handling.

Class Overview

Extended file upload form control with some automatic file and error handling.

Public Static Methods

static make_unique($path, $filename, $max=99) [static]

Returns a filename which is unique in the given path.

FIXME: might not be the proper place for this function.

Parameters

$path

The path where to check the file.

$filename

The base filename.

$max

The maximum number of iterations to try. Defaults to 99.

Return value

If the file doesn't already exist, it will return $filename, otherwise it will return basename.N.ext where N is the lowest value for which the a filename doesn't exist yet.

Will return false if N were to grow larger than $max.

Public Methods

__construct($name, $uploaddir)

Create a new file upload control.

Parameters

$name

The name of this control.

$uploaddir

The directory to upload the files to.

build_widget()

Render the minimal HTML needed for this control to work.

Form control implementations should implement this method, e.g. for a checkbox a simple input HTML element should be returned.

Return value

XHTML element with the minimal HTML markup needed for this control to function properly.

get_fileinfo()

Returns information about the upload.

This will be the contents of $_FILES[$control_name] or null if that does not exist.

get_filename()

Returns the name of the file uploaded by the user.

process()

Process this fileupload.

This will put the file in the $uploaddir directory.

fill($values)

Set the value by the filename of the uploaded file, but only if a file is uploaded.

Validation methods

is_valid()

Check whether this form control is valid.

The default is to apply all validators added to this control. Subclasses could also override this method to do something more sensible than applying validators, since some controls don't accept validators, e.g. checkboxes.

Return value

True if valid, false otherwise.

Inheritance

Base Classes

Inherited members