| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class HTML_QuickForm2_Element_InputFile extends HTML_QuickForm2_Element_Input |
| { |
| |
| |
| |
| const DEFAULT_LANGUAGE = 'en'; |
|
|
| |
| |
| |
| |
| protected $errorMessages = array( |
| 'en' => array( |
| UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds size permitted by PHP configuration (%d bytes)', |
| UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive in HTML form (%d bytes)', |
| UPLOAD_ERR_PARTIAL => 'The file was only partially uploaded', |
| UPLOAD_ERR_NO_TMP_DIR => 'Server error: temporary directory is missing', |
| UPLOAD_ERR_CANT_WRITE => 'Server error: failed to write the file to disk', |
| UPLOAD_ERR_EXTENSION => 'File upload was stopped by extension' |
| ), |
| 'fr' => array( |
| UPLOAD_ERR_INI_SIZE => 'Le fichier envoyé excède la taille autorisée par la configuration de PHP (%d octets)', |
| UPLOAD_ERR_FORM_SIZE => 'Le fichier envoyé excède la taille de MAX_FILE_SIZE spécifiée dans le formulaire HTML (%d octets)', |
| UPLOAD_ERR_PARTIAL => 'Le fichier n\'a été que partiellement téléchargé', |
| UPLOAD_ERR_NO_TMP_DIR => 'Erreur serveur: le répertoire temporaire est manquant', |
| UPLOAD_ERR_CANT_WRITE => 'Erreur serveur: échec de l\'écriture du fichier sur le disque', |
| UPLOAD_ERR_EXTENSION => 'L\'envoi de fichier est arrêté par l\'extension' |
| ), |
| 'ru' => array( |
| UPLOAD_ERR_INI_SIZE => 'Размер загруженного файла превосходит максимально разрешённый настройками PHP (%d байт)', |
| UPLOAD_ERR_FORM_SIZE => 'Размер загруженного файла превосходит директиву MAX_FILE_SIZE, указанную в форме (%d байт)', |
| UPLOAD_ERR_PARTIAL => 'Файл был загружен не полностью', |
| UPLOAD_ERR_NO_TMP_DIR => 'Ошибка на сервере: отсутствует каталог для временных файлов', |
| UPLOAD_ERR_CANT_WRITE => 'Ошибка на сервере: не удалось записать файл на диск', |
| UPLOAD_ERR_EXTENSION => 'Загрузка файла была остановлена расширением' |
| ) |
| ); |
|
|
| |
| |
| |
| |
| protected $language; |
|
|
| |
| |
| |
| |
| protected $value = null; |
|
|
| protected $attributes = array('type' => 'file'); |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function __construct($name = null, $attributes = null, array $data = array()) |
| { |
| if (isset($data['errorMessages'])) { |
| |
| foreach ($data['errorMessages'] as $lang => $ary) { |
| foreach ($ary as $code => $message) { |
| $this->errorMessages[$lang][$code] = $message; |
| } |
| } |
| unset($data['errorMessages']); |
| } |
| if (!isset($data['language'])) { |
| $this->language = self::DEFAULT_LANGUAGE; |
| } else { |
| $this->language = isset($this->errorMessages[$data['language']])? |
| $data['language']: self::DEFAULT_LANGUAGE; |
| unset($data['language']); |
| } |
| parent::__construct($name, $attributes, $data); |
| } |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function toggleFrozen($freeze = null) |
| { |
| return false; |
| } |
|
|
| |
| |
| |
| |
| |
| public function getValue() |
| { |
| return $this->value; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function setValue($value) |
| { |
| return $this; |
| } |
|
|
| public function updateValue() |
| { |
| foreach ($this->getDataSources() as $ds) { |
| if ($ds instanceof HTML_QuickForm2_DataSource_Submit) { |
| $value = $ds->getUpload($this->getName()); |
| if (null !== $value) { |
| $this->value = $value; |
| return; |
| } |
| } |
| } |
| $this->value = null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function validate() |
| { |
| if (strlen($this->error ?? '')) { |
| return false; |
| } |
| if (isset($this->value['error']) && |
| !in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE))) |
| { |
| if (isset($this->errorMessages[$this->language][$this->value['error']])) { |
| $errorMessage = $this->errorMessages[$this->language][$this->value['error']]; |
| } else { |
| $errorMessage = $this->errorMessages[self::DEFAULT_LANGUAGE][$this->value['error']]; |
| } |
| if (UPLOAD_ERR_INI_SIZE == $this->value['error']) { |
| $iniSize = ini_get('upload_max_filesize'); |
| $size = intval($iniSize); |
| switch (strtoupper(substr($iniSize, -1))) { |
| case 'G': $size *= 1024; |
| case 'M': $size *= 1024; |
| case 'K': $size *= 1024; |
| } |
|
|
| } elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) { |
| foreach ($this->getDataSources() as $ds) { |
| if ($ds instanceof HTML_QuickForm2_DataSource_Submit) { |
| $size = intval($ds->getValue('MAX_FILE_SIZE')); |
| break; |
| } |
| } |
| } |
| $this->error = isset($size)? sprintf($errorMessage, $size): $errorMessage; |
| return false; |
| } |
| return parent::validate(); |
| } |
|
|
| public function addFilter($callback, ?array $options = null, $recursive = true) |
| { |
| throw new HTML_QuickForm2_Exception( |
| 'InputFile elements do not support filters' |
| ); |
| } |
| } |
| ?> |
|
|