Class \Prado\Web\UI\WebControls\TFileUpload
TFileUpload displays a file upload field on a page. Upon postback, the selected files will be uploaded to the server. The property \Prado\Web\UI\WebControls\getHasFile indicates whether the file upload is successful. If successful, the file may be obtained by calling saveAs to save it at a specified place. You can use \Prado\Web\UI\WebControls\getFileName, \Prado\Web\UI\WebControls\getFileType, \Prado\Web\UI\WebControls\getFileSize to get the original client-side file name, the file mime type, and the file size information. If the upload is not successful, \Prado\Web\UI\WebControls\getErrorCode contains the error code describing the cause of failure.
Since Prado 4.0 the TFileUpload supports uploading multiple files at once by setting \Prado\Web\UI\WebControls\setMultiple to true which renders the additional HTML5 attribute and adds square brackets to the name attribute. A new method getFiles is introduced which returns an array of TFileUploadItem representing each uploaded file.
All (old) methods mentioned in the first paragraph (getHasFile, getFileName, getFileType, getFileSize, getErrorCode and saveAs) also take a new optional parameter specifying the file index to get the desired information from. This is for backward compatibility so that old, single file uploads will still work - internally a TFileUploadItem is also used for a single file upload. If more than one file is uploaded getValidationPropertyValue returns a comma separated list of original file names instead of a single file name for validation.
TFileUpload raises \Prado\Web\UI\WebControls\onFileUpload event if one or more files are uploaded (whether it succeeds or not).
Class hierarchy
- \Prado\Web\UI\WebControls\TFileUpload implements IPostBackDataHandler, IValidatable
- \Prado\Web\UI\WebControls\TWebControl implements IStyleable
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
Author: LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
Since: 3.0
public
|
getDataChanged() : bool
Returns a value indicating whether postback has caused the control data change.
This method is required by the \Prado\Web\UI\IPostBackDataHandler interface. |
public
|
getErrorCode([int $index = 0 ]) : int
Returns an error code describing the status of this file uploading.
For backward compatibility, the first file is used by default. |
public
|
getFileName([int $index = 0 ]) : string
For backward compatibility, the first file is used by default.
|
public
|
|
public
|
|
public
|
getFileType([int $index = 0 ]) : string
For backward compatibility, the first file is used by default.
|
public
|
getHasAllFiles() : bool
This method is used for multiple file uploads to indicate if all files were uploaded succsessfully.
|
public
|
|
public
|
|
public
|
getLocalName([int $index = 0 ]) : string
For backward compatibility, the first file is used by default.
|
public
|
|
public
|
|
public
|
getValidationPropertyValue() : string
Returns the comma separated list of original file names as the property value to be validated.
This method is required by \Prado\Web\UI\IValidatable property. |
public
|
loadPostData(string $key, array<string|int, mixed> $values) : bool
Loads user input data.
This method is primarly used by framework developers. |
public
|
onFileUpload(TEventParameter $param) : mixed
This method is invoked when a file is uploaded during a postback.
The method raises OnFileUpload event to fire up the event handler. If you override this method, be sure to call the parent implementation so that the event delegates can be invoked. |
public
|
onPreRender(mixed $param) : mixed
Sets Enctype of the form on the page.
This method overrides the parent implementation and is invoked before render. |
public
|
raisePostDataChangedEvent() : mixed
Raises postdata changed event.
This method calls onFileUpload method. This method is primarly used by framework developers. |
public
|
saveAs(string $fileName[, bool $deleteTempFile = true ][, int $index = 0 ]) : bool
Saves the uploaded file.
Returns an error code describing the status of this file uploading. For backward compatibility, the first file is used by default. |
public
|
|
public
|
setMaxFileSize(int $size) : mixed
Sets the maximum size that a file can be uploaded.
Note, this is an advisory value to the browser. Sets this property with a reasonably large size to save users the trouble of waiting for a big file being transferred only to find that it was too big and the transfer failed. |
public
|
|
protected
|
addAttributesToRender(THtmlWriter $writer) : mixed
Sets name attribute to the unique ID of the control.
This method overrides the parent implementation with additional file update control specific attributes. |
protected
|
public
mixed
|
MAX_FILE_SIZE
Maximum file size (in bytes) allowed to be uploaded, defaults to 1MB.
|
1048576
|