FORMfields


FORMfields.fields.UploadField

Class UploadField

FormField
|
+--FileField
|
+--UploadField

public class UploadField
extends FileField

UploadField is a field for selecting a file on your local computer to upload to your web server. Note: To utilize this field, you must use method="post" and enctype="multipart/form-data" in your form tag.

Since:
FORMfields v1.0

Field Summary
mixed

$allowAllExts

True if all files, even those with prohibited extensions can be uploaded.

mixed

$clearButton

The sub field for the clear button, that clears the upload.

mixed

$enableUploadNow

True if the upload now button should be displayed and activated.

mixed

$fileProperties

The value of PHP's $_FILES array: name, type, size, tmp_name, error as set by PHP when a file has been successfully uploaded.

mixed

$maxFileSize

The max file size in bytes permitted.

mixed

$newUpload

True if a file has already been uploaded or false otherwise.

mixed

$prohibitedExts

An array of partial extensions that cannot be uploaded with this field.

mixed

$subFieldsCannotBeEmpty

True if an empty sub field constitutes an invalid value.

mixed

$uploadDir

The local path to the directory where this file should be uploaded.

mixed

$uploadDirUrl

The URL to the directory where this file should be uploaded.

mixed

$uploadNowButton

The sub field for the upload button that uploads the file now, instead of waiting for the entire form to be submitted to upload the file.

mixed

$uploadedFile

The URL to the uploaded file.

mixed

$uploadedFileField

A sub field for propagating uploadedFile.

mixed

$uploadedFilename

The filename of the uploaded file.

mixed

$uploadedLocalFile

The local path to the uploaded file.

Fields inherited from FORMfields.fields.FileField
MAX_SIZE
Fields inherited from FORMfields.fields.FormField
autoPropagate, data, disableEnterHandler, displayValuesOnNewLine, editable, enabled, endingString, enterTabHandler, enterTabs, error, extraHtml, fieldBelowLabel, formError, help, hidden, htmlify, id, isData, label, labelForId, multiValues, name, required, subFieldDisplayValueSeparator, subFieldSeparator, subFieldValueSeparator, subFields, subFieldsCannotBeEmpty, trimWhitespace, validators, value, valueIsHtml
Constructor Summary

UploadField(string name, string label, int required, int maxFileSize, int uploadDir, int uploadDirUrl)

Creates a new UploadField.

__construct(string name, string label, int required, int maxFileSize, int uploadDir, int uploadDirUrl)

Creates a new UploadField.

Method Summary
string

getDisplayHtmlValue()

Returns a hyperlink to the uploaded file.

string

getEditableFieldTag()

Returns the HTML used to display the input portion of this field.

void

getParameter()

Retrieves the posted field value.

mixed

getValue()

Returns the value of this form field.

boolean

isValid()

Checks for field errors detected by this field, including a check for blank.

void

moveUploadedFile(string destination)

Moves the uploaded field to the destination path.

void

setValue(string value)

Sets the database value of this field.

void

uploadFile()

This method checks for any errors that may have occured while trying to upload the file.

boolean

validExtension(string ext)

Returns true if the specified extension is an extension that may be uploaded.

Methods inherited from FORMfields.fields.FileField
getEditableFieldTag
Methods inherited from FORMfields.fields.FormField
addFieldValidator, addSubField, checkForBlank, clearValue, disable, formatRequestParameter, formatText, getButtonClicked, getData, getDbValue, getDisableFieldJs, getDisableJs, getDisableLabelJs, getDisplayFieldTag, getDisplayHtmlValue, getDisplayLabelTag, getDisplayValue, getEditable, getEditableFieldTag, getEditableLabelTag, getEnabled, getError, getExtraHtml, getFieldTag, getFormError, getHelp, getHelpTag, getHidden, getHiddenFieldTag, getId, getIsData, getIsHidden, getLabel, getLabelHtml, getLabelTag, getName, getOrNull, getParameter, getRawDbValue, getRequired, getValue, isBlank, isEmpty, isValid, setAutoPropagate, setData, setDbValue, setDisplayValuesOnNewLine, setEditable, setEnabled, setEndingString, setError, setExtraHtml, setFieldBelowLabel, setFormError, setHelp, setHidden, setHtmlify, setId, setIsData, setIsHidden, setLabel, setName, setRequired, setTrimWhitespace, setValue, setValueIsHtml, validate

Field Detail

allowAllExts

public mixed $allowAllExts = false

True if all files, even those with prohibited extensions can be uploaded.

Since:
FORMfields v1.0

clearButton

public mixed $clearButton = null

The sub field for the clear button, that clears the upload. Note: Clicking the clear button doesn't delete the uploaded file.

Since:
FORMfields v1.0

enableUploadNow

public mixed $enableUploadNow = true

True if the upload now button should be displayed and activated.

Since:
FORMfields v1.0

fileProperties

public mixed $fileProperties

The value of PHP's $_FILES array: name, type, size, tmp_name, error as set by PHP when a file has been successfully uploaded.

Since:
FORMfields v1.0

maxFileSize

public mixed $maxFileSize

The max file size in bytes permitted.

Since:
FORMfields v1.0

newUpload

public mixed $newUpload = false

True if a file has already been uploaded or false otherwise.

Since:
FORMfields v1.0

prohibitedExts

public mixed $prohibitedExts = array("php"

An array of partial extensions that cannot be uploaded with this field. This array should contain the extensions all files that can be executed on your web server. In this regard a file cannot be uploaded to your FORMfields/uploads directory and then executed using a web browser to perform malicious activities.

Since:
FORMfields v1.0

subFieldsCannotBeEmpty

public mixed $subFieldsCannotBeEmpty = false

True if an empty sub field constitutes an invalid value.

Since:
FORMfields v3.0

uploadDir

public mixed $uploadDir

The local path to the directory where this file should be uploaded. If this parameter is omitted, the file will be uploaded to /FORMfields/uploads.

Since:
FORMfields v1.0

uploadDirUrl

public mixed $uploadDirUrl

The URL to the directory where this file should be uploaded. If this parameter is omitted, the file will be uploaded to your FORMfields/uploads directory.

Since:
FORMfields v1.0

uploadNowButton

public mixed $uploadNowButton = null

The sub field for the upload button that uploads the file now, instead of waiting for the entire form to be submitted to upload the file.

Since:
FORMfields v1.0

uploadedFile

public mixed $uploadedFile

The URL to the uploaded file.

Since:
FORMfields v1.0

uploadedFileField

public mixed $uploadedFileField

A sub field for propagating uploadedFile.

Since:
FORMfields v3.0

uploadedFilename

public mixed $uploadedFilename

The filename of the uploaded file.

Since:
FORMfields v1.0

uploadedLocalFile

public mixed $uploadedLocalFile

The local path to the uploaded file.

Since:
FORMfields v1.0

Constructor Detail

UploadField

public UploadField(string name, string label, int required, int maxFileSize, int uploadDir, int uploadDirUrl)

Creates a new UploadField.

Parameters:
name - the name of the form field. This value must not be a SQL reserved word and should follow all the standard variable naming conventions in PHP.
label - this form field's label. The label is the printable text that is typically displayed on the left side of the field.
required - Sets whether the field must be filled in and whether it looks like it must be filled in: FORM_FIELD_REQUIRED, FORM_FIELD_NOT_REQUIRED, FORM_FIELD_LOOKS_REQUIRED or FORM_FIELD_REQUIRED_NO_LOOK
maxFileSize - The max file size in bytes permitted. If this parameter is omitted or null, the max default size will be 2 MB.
uploadDir - The local path to the directory where this file should be uploaded. If this parameter is omitted or null, the file will be uploaded to the FORMfields/uploads directory.
uploadDirUrl - The URL to the directory where this file should be uploaded. If this parameter is omitted or null, the file will be uploaded to the FORMfields/uploads directory.
See Also:
FORM_FIELD_REQUIRED
FORM_FIELD_NOT_REQUIRED
FORM_FIELD_LOOKS_REQUIRED
FORM_FIELD_REQUIRED_NO_LOOK
Since:
FORMfields v1.0
Deprecated:
deprecated as this constructor syntax is not expected in PHP 5 - will be removed once PHP 5 becomes a minimum requirement for FORMfields

Method Detail

getDisplayHtmlValue

public string getDisplayHtmlValue()

Returns a hyperlink to the uploaded file.

Returns:
a hyperlink to the uploaded file
Since:
FORMfields v1.0

getEditableFieldTag

public string getEditableFieldTag()

Returns the HTML used to display the input portion of this field.

Returns:
the HTML used to display the input portion of this field
Since:
FORMfields v1.0

getParameter

public void getParameter()

Retrieves the posted field value. In other words, sets this field value using the appropriate values in $_REQUEST.

Since:
FORMfields v1.0

getValue

public mixed getValue()

Returns the value of this form field. Needed to override the parent method.

Returns:
the value of this form field.
Since:
FORMfields v3.0

isValid

public boolean isValid()

Checks for field errors detected by this field, including a check for blank. This method checks for any errors that may have occured while trying to upload the file. If an error is detected, the setError() method is called to set the appropriate error message.

Returns:
true if there is an error or false otherwise
Since:
FORMfields v1.0

moveUploadedFile

public void moveUploadedFile(string destination)

Moves the uploaded field to the destination path. Note: some web servers don't permit you to move an uploaded file, but they do permit you to copy an uploaded file.

Parameters:
destination - the local path to the destination path
Since:
FORMfields v1.0

setValue

public void setValue(string value)

Sets the database value of this field. A database value can be different than the field's actual value. For example a phone number may have the value "973-746-3233" but its database value would be "9737463233"

Parameters:
value - an absolute URL to the uploaded file
Since:
FORMfields v1.0

uploadFile

public void uploadFile()

This method checks for any errors that may have occured while trying to upload the file. It also checks for any invalid file extensions: "php", "phtml", "asp", "jsp", "py" or "cfm". Upon a successful upload, this method copies the file to the uploads directory.

Since:
FORMfields v3.0

validExtension

public boolean validExtension(string ext)

Returns true if the specified extension is an extension that may be uploaded. Filenames like "myfile.php.disabled" that could otherwise be executed with PHP will pass validation with validExtension(), however a timestamp is appended to these filenames during upload and as a side effect of this, PHP will not execute these uploaded files.

Parameters:
ext - the extension to check
Returns:
true if the specified extension is an extension that may be uploaded
Since:
FORMfields v1.0

FORMfields