public function validate($value) { $ret = (array) parent::validate($value); if ($ret[0] == false) { return $ret; } // Consider required and optional situations. if ($fileArg = $this->action->request->file($this->name)) { $file = UploadedFile::createFromArray($fileArg); // If valid extensions are specified, pass to uploaded file to check the extension if ($this->validExtensions) { if (!$file->validateExtension($this->validExtensions)) { // return array(false, __('Invalid File Extension: %1' . $this->name ) ); return array(false, $this->action->messagePool->translate('Invalid File Extension: %1'), $this->name); } } if ($this->sizeLimit) { if (!$file->validateSize($this->sizeLimit)) { return array(false, $this->action->messagePool->translate("The uploaded file exceeds the size limitation. %1 KB ", futil_prettysize($this->sizeLimit))); } } } return true; }
public function validate($value) { $ret = (array) parent::validate($value); if (false === $ret[0]) { return $ret; } $requireUploadMove = false; $uploadedFile = $this->_findUploadedFile($this->name, $requireUploadMove); if ($uploadedFile && $uploadedFile->hasError()) { return [false, $uploadedFile->getUserErrorMessage()]; } $file = $this->action->request->file($this->name); if (!empty($file) && $file['name'] && $file['type']) { $uploadedFile = UploadedFile::createFromArray($file); if ($this->validExtensions) { if (!$uploadedFile->validateExtension($this->validExtensions)) { return [false, _('Invalid file extension: ') . $uploadedFile->getExtension()]; } } if ($this->sizeLimit) { if (!$uploadedFile->validateSize($this->sizeLimit)) { return [false, _("The uploaded file exceeds the size limitation. ") . futil_prettysize($this->sizeLimit * 1024)]; } } } else { if ($this->required) { return [false, "Field {$this->name} is required."]; } } return true; }