Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

(no description)

File Size: 355 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

HTML_QuickForm_file:: (2 methods):
  __construct()
  HTML_QuickForm_file()

name:: (13 methods):
  setSize()
  getSize()
  freeze()
  setValue()
  getValue()
  onQuickFormEvent()
  moveUploadedFile()
  isUploadedFile()
  _ruleIsUploadedFile()
  _ruleCheckMaxFileSize()
  _ruleCheckMimeType()
  _ruleCheckFileName()
  _findValue()


Class: HTML_QuickForm_file  - X-Ref

HTML class for a file type element

__construct($elementName=null, $elementLabel=null, $attributes=null)   X-Ref
Class constructor

param: string    Input field name attribute
param: string    Input field label
param: mixed     (optional)Either a typical HTML attribute string

HTML_QuickForm_file($elementName=null, $elementLabel=null, $attributes=null)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

setSize($size)   X-Ref
Sets size of file element

param: int    Size of file element

getSize()   X-Ref
Returns size of file element

return: int

freeze()   X-Ref
Freeze the element so that only its value is returned

return: bool

setValue($value)   X-Ref
Sets value for file element.

Actually this does nothing. The function is defined here to override
HTML_Quickform_input's behaviour of setting the 'value' attribute. As
no sane user-agent uses <input type="file">'s value for anything
(because of security implications) we implement file's value as a
read-only property with a special meaning.

param: mixed    Value for file element

getValue()   X-Ref
Returns information about the uploaded file

return: array

onQuickFormEvent($event, $arg, &$caller)   X-Ref
Called by HTML_QuickForm whenever form event is made on this element

param: string    Name of event
param: mixed     event arguments
param: object    calling object
return: bool

moveUploadedFile($dest, $fileName = '')   X-Ref
Moves an uploaded file into the destination

param: string  Destination directory path
param: string  New file name
return: bool    Whether the file was moved successfully

isUploadedFile()   X-Ref
Checks if the element contains an uploaded file

return: bool      true if file has been uploaded, false otherwise

_ruleIsUploadedFile($elementValue)   X-Ref
Checks if the given element contains an uploaded file

param: array     Uploaded file info (from $_FILES)
return: bool      true if file has been uploaded, false otherwise

_ruleCheckMaxFileSize($elementValue, $maxSize)   X-Ref
Checks that the file does not exceed the max file size

param: array     Uploaded file info (from $_FILES)
param: int       Max file size
return: bool      true if filesize is lower than maxsize, false otherwise

_ruleCheckMimeType($elementValue, $mimeType)   X-Ref
Checks if the given element contains an uploaded file of the right mime type

param: array     Uploaded file info (from $_FILES)
param: mixed     Mime Type (can be an array of allowed types)
return: bool      true if mimetype is correct, false otherwise

_ruleCheckFileName($elementValue, $regex)   X-Ref
Checks if the given element contains an uploaded file of the filename regex

param: array     Uploaded file info (from $_FILES)
param: string    Regular expression
return: bool      true if name matches regex, false otherwise

_findValue()   X-Ref
Tries to find the element value from the values array

Needs to be redefined here as $_FILES is populated differently from
other arrays when element name is of the form foo[bar]

return: mixed