Prado\Web\UI\WebControls\TFileUpload::onPreRender PHP Method

onPreRender() public method

This method overrides the parent implementation and is invoked before render.
public onPreRender ( $param )
    public function onPreRender($param)
    {
        parent::onPreRender($param);
        if (($form = $this->getPage()->getForm()) !== null) {
            $form->setEnctype('multipart/form-data');
        }
        $this->getPage()->getClientScript()->registerHiddenField('MAX_FILE_SIZE', $this->getMaxFileSize());
        if ($this->getEnabled(true)) {
            $this->getPage()->registerRequiresPostData($this);
        }
    }

Usage Example

Beispiel #1
0
    /**
     * Publish the javascript
     */
    public function onPreRender($param)
    {
        parent::onPreRender($param);
        if (!$this->getPage()->getIsPostBack() && isset($_GET['TActiveFileUpload_InputId']) && isset($_GET['TActiveFileUpload_TargetId']) && $_GET['TActiveFileUpload_InputId'] == $this->getClientID()) {
            // tricky workaround to intercept "uploaded file too big" error: real uploads happens in onFileUpload instead
            $this->_errorCode = UPLOAD_ERR_FORM_SIZE;
            $localName = str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()), ''));
            $fileName = addslashes($this->getFileName());
            $params = new TActiveFileUploadCallbackParams();
            $params->localName = $localName;
            $params->fileName = $fileName;
            $params->fileSize = $this->getFileSize();
            $params->fileType = $this->getFileType();
            $params->errorCode = $this->getErrorCode();
            echo <<<EOS
<script language="Javascript">
\tOptions = new Object();
\tOptions.clientID = '{$_GET['TActiveFileUpload_InputId']}';
\tOptions.targetID = '{$_GET['TActiveFileUpload_TargetId']}';
\tOptions.fileName = '{$params->fileName}';
\tOptions.fileSize = '{$params->fileSize}';
\tOptions.fileType = '{$params->fileType}';
\tOptions.errorCode = '{$params->errorCode}';
\tOptions.callbackToken = '{$this->pushParamsAndGetToken($params)}';
\tparent.Prado.WebUI.TActiveFileUpload.onFileUpload(Options);
</script>
EOS;
        }
    }