Class FileField
Represents a file type which can be added to a form. Automatically tries to save has_one-relations on the saved record.
Please set a validator on the form-object to get feedback about imposed filesize/extension restrictions.
CAUTION: Doesn't work in the CMS due to ajax submission, please use FileIFrameField instead.
If you want to implement a FileField into a form element, you need to pass it an array of source data.
class ExampleForm_Controller extends Page_Controller { public function Form() { $fields = new FieldSet( new TextField('MyName'), new FileField('MyFile') ); $actions = new FieldSet( new FormAction('doUpload', 'Upload file') ); $validator = new RequiredFields(array('MyName', 'MyFile')); return new Form($this, 'Form', $fields, $actions, $validator); } function doUpload($data, $form) { $file = $data['MyFile']; $content = file_get_contents($file['tmp_name']); // ... process content } }
- Object
-
ViewableData
implements
IteratorAggregate
-
RequestHandler
-
FormField
-
FileField
Direct known subclasses
Indirect known subclasses
Methods summary
public
|
#
__construct( string $name, string $title = null, integer $value = null,
Create a new file field. |
public
|
#
Field( )
Returns the form field - used by templates. Although FieldHolder is generally what is inserted into templates, all of the field holder templates make use of $Field. It's expected that FieldHolder will give you the "complete" representation of the field on the form, whereas Field will give you the core editing widget, such as an input tag. |
public
|
#
saveInto(
Method to save this form field into the given data object. By default, makes use of $this->dataValue() |
public
|
|
public
|
|
public
|
|
public
integer
|
#
getAllowedMaxFileSize( string $ext = null )
Get maximum file size for all or specified file extension. Falls back to the default filesize restriction ('*') if the extension was not found. |
public
|
#
setAllowedMaxFileSize( unknown_type $rules )
Set filesize maximums (in bytes). Automatically converts extensions to lowercase for easier matching. |
public
array
|
|
public
|
|
public
|
|
public
string
|
|
public
|
Methods inherited from FormField
FieldHolder(),
LeftTitle(),
Link(),
Message(),
MessageType(),
Name(),
Required(),
RightTitle(),
SmallFieldHolder(),
Title(),
Type(),
addExtraClass(),
attrName(),
attrTitle(),
attrValue(),
createTag(),
dataValue(),
debug(),
describe(),
extraClass(),
forTemplate(),
getCustomValidationMessage(),
getForm(),
getTabIndex(),
getTabIndexHTML(),
hasClass(),
hasData(),
id(),
isComposite(),
isDisabled(),
isReadonly(),
jsValidation(),
name_to_label(),
performDisabledTransformation(),
performReadonlyTransformation(),
removeExtraClass(),
rootFieldSet(),
securityTokenEnabled(),
setContainerFieldSet(),
setCustomValidationMessage(),
setDisabled(),
setError(),
setForm(),
setLeftTitle(),
setName(),
setReadonly(),
setRightTitle(),
setTabIndex(),
setTitle(),
setValue(),
transform()
Methods inherited from RequestHandler
allowedActions(),
checkAccessAction(),
getRequest(),
handleRequest(),
hasAction(),
httpError()
Methods inherited from ViewableData
ATT_val(),
BaseHref(),
CSSClasses(),
CurrentMember(),
CurrentPage(),
Debug(),
Even(),
EvenOdd(),
First(),
FirstLast(),
HasPerm(),
IsAjax(),
JS_val(),
Last(),
Me(),
Middle(),
MiddleString(),
Modulus(),
MultipleOf(),
Odd(),
Pos(),
RAW_val(),
SQL_val(),
ThemeDir(),
Top(),
TotalItems(),
XML_val(),
__get(),
__isset(),
__set(),
buildCastingCache(),
cachedCall(),
castingClass(),
castingHelper(),
castingHelperPair(),
castingObjectCreator(),
castingObjectCreatorPair(),
customise(),
defineMethods(),
escapeTypeForField(),
getField(),
getIterator(),
getSecurityID(),
getXMLValues(),
hasField(),
hasValue(),
i18nLocale(),
iteratorProperties(),
obj(),
renderWith(),
setCustomisedObj(),
setField()
Methods inherited from Object
__call(),
__toString(),
addMethodsFrom(),
addStaticVars(),
addWrapperMethod(),
add_extension(),
add_static_var(),
allMethodNames(),
cacheToFile(),
cacheToFileWithArgs(),
clearCache(),
combined_static(),
create(),
createMethod(),
create_from_string(),
exists(),
extInstance(),
extend(),
getCustomClass(),
getExtensionInstance(),
getExtensionInstances(),
get_extensions(),
get_static(),
hasExtension(),
hasMethod(),
has_extension(),
invokeWithExtensions(),
is_a(),
loadCache(),
parentClass(),
parse_class_spec(),
remove_extension(),
sanitiseCachename(),
saveCache(),
set_stat(),
set_static(),
set_uninherited(),
stat(),
strong_create(),
uninherited(),
uninherited_static(),
useCustomClass()
Magic methods summary
Properties summary
public
array
|
$allowedMaxFileSize |
#
Restrict filesize for either all filetypes or a specific extension, with extension-name as array-key and the size-restriction in bytes as array-value. |
public
array
|
$allowedExtensions |
#
Collection of extensions. Extension-names are treated case-insensitive. Example: array("jpg","GIF") |
public
boolean
|
$relationAutoSetting |
#
Flag to automatically determine and save a has_one-relationship on the saved record (e.g. a "Player" has_one "PlayerImage" would trigger saving the ID of newly created file into "PlayerImageID" on the record). |
protected
|
$upload |
#
Upload object (needed for validation and actually moving the temporary file created by PHP). |
protected
string
|
$folderName |
#
Partial filesystem path relative to /assets directory. Defaults to 'Uploads'. |
Properties inherited from FormField
$containerFieldSet,
$customValidationMessage,
$description,
$disabled,
$dontEscape,
$extraClass,
$extraClasses,
$form,
$leftTitle,
$message,
$messageType,
$name,
$readonly,
$rightTitle,
$tabIndex,
$title,
$value
Properties inherited from RequestHandler
$allowed_actions,
$brokenOnConstruct,
$request,
$url_handlers
Properties inherited from ViewableData
$casting,
$customisedObject,
$default_cast,
$failover,
$iteratorPos,
$iteratorTotalItems
Comments
Use the Silverstripe Forum to ask questions.