12define(
"UPLOAD_ERR_FILE_EXTENSION", 1000);
49 parent::setDefaults();
52 $this->defaults[
'maxNum'] = 1;
53 $this->defaults[
'maxSize'] =
false;
54 $this->defaults[
'allowedExtensions'] =
"";
64 if ($this->maxSize !==
false) {
65 $maxInput =
"<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$this->maxSize}\" />";
73 $label = $this->htmlLabel();
79 return "<p {$wrapperAttributes}>" .
81 "<span class=\"depage-label\">{$label}{$marker}</span>" .
83 "<input name=\"{$this->name}[]\" type=\"{$this->type}\"{$inputAttributes}>" .
97 $attributes = parent::htmlInputAttributes();
99 if ($this->maxNum > 1) {
100 $attributes .=
" multiple=\"multiple\"";
102 if (!empty($this->allowedExtensions)) {
103 $attributes .=
" accept=\"" . htmlentities($this->allowedExtensions) .
"\"";
116 $this->value = (array) $this->value;
126 if (!is_array($files)) {
130 if (!empty($this->allowedExtensions)) {
131 $extRegex = str_replace(array(
" ",
",",
"."), array(
"",
"|",
"\."), $this->allowedExtensions);
133 if (isset($_FILES[$this->name])) {
134 foreach ($_FILES[$this->name][
"error"] as $key => $error) {
135 if (!empty($extRegex) && !preg_match(
"/.*(" . $extRegex .
")$/i", $_FILES[$this->name][
"name"][$key])) {
138 if ($error == UPLOAD_ERR_OK) {
139 $uploadName = $_FILES[
$this->name][
"tmp_name"][$key];
140 $tmpName = tempnam(
"",
"depage-form-upload-");
141 $success = move_uploaded_file($uploadName, $tmpName);
142 if ($this->maxNum > 1) {
144 'name' => $_FILES[$this->name][
"name"][$key],
145 'tmp_name' => $tmpName,
150 'name' => $_FILES[$this->name][
"name"][$key],
151 'tmp_name' => $tmpName,
156 UPLOAD_ERR_INI_SIZE =>
"The uploaded file exceeds the upload_max_filesize directive in php.ini.",
157 UPLOAD_ERR_FORM_SIZE =>
"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
158 UPLOAD_ERR_PARTIAL =>
"The uploaded file was only partially uploaded.",
159 UPLOAD_ERR_NO_FILE =>
"No file was uploaded.",
160 UPLOAD_ERR_NO_TMP_DIR =>
"Missing a temporary folder.",
161 UPLOAD_ERR_CANT_WRITE =>
"Failed to write file to disk.",
162 UPLOAD_ERR_EXTENSION =>
"A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop.",
165 $this->
log(
"htmlform: " . $errorMsgs[$error]);
173 $this->value = array_slice($files, - $this->maxNum, $this->maxNum);
187 $this->value = array();
197 if (count($this->value)) {
198 foreach ($this->value as $file) {
199 if (file_exists($file[
'tmp_name'])) {
200 unlink($file[
'tmp_name']);
log($argument, $type=null)
error & warning logger
$label
Input element - HTML label.
$errorMessage
Message that gets displayed in case of invalid input.
htmlHelpMessage()
Returns HTML-rendered helpMessage.
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
htmlMarker()
Returns elements' required-indicator.
$helpMessage
Extra help message.
htmlValue()
Returns HTML-rendered element value.
$marker
Input element - HTML marker text that marks required fields.
htmlErrorMessage()
Returns HTML-rendered error message.
htmlInputAttributes()
renders text element specific HTML attributes
$maxSize
HTML maxSize attribute.
clearValue()
resets the value to en empty array and cleans uploaded files
typeCastValue()
Converts value to element specific type.
$maxNum
HTML maxNum attribute.
handleUploadedFiles($files=null)
saves uploaded files
__toString()
Renders element to HTML.
clearUploadedFiles()
cleans uploaded files when session is cleared
$allowedExtensions
HTML allowedExtensions attribute.
setDefaults()
collects initial values across subclasses
htmlList($options=null)
Renders HTML datalist.
Classes for HTML input-elements.
const UPLOAD_ERR_FILE_EXTENSION