19 declare(strict_types=1);
46 string $a_postvar =
"" 50 $this->
lng = $DIC->language();
51 $this->
lng->loadLanguageModule(
'form');
53 $this->upload_service = $DIC->upload();
54 $this->upload_limit = $DIC[
'ui.upload_limit_resolver'];
63 $value = $a_values[$this->
getPostVar()] ?? null;
64 if (!is_array($value)) {
74 public function setValue(
string $a_value): void
76 $this->value = $a_value;
84 public function setSize(
int $a_size): void
86 $this->size = $a_size;
97 $this->filename = $a_val;
107 $this->suffixes = $a_suffixes;
117 $this->forbidden_suffixes = $a_suffixes;
128 $this->pending = $a_val;
139 $this->filename_selection =
true;
140 $this->filename_post = $a_post_var;
155 $this->allow_deletion = $a_val;
165 if (!$this->upload_service->hasBeenProcessed()) {
167 $this->upload_service->process();
182 $this->
setAlert($this->
lng->txt(
"form_msg_file_size_exceeds"));
188 $utf_normal = $this->
refinery->string()->utfnormal()->formC();
189 $_FILES[$this->
getPostVar()][
"name"] = $utf_normal->transform(($_FILES[$this->
getPostVar()][
"name"]));
194 $filename = $_FILES[$this->
getPostVar()][
"name"];
195 $filename_arr = pathinfo($_FILES[$this->
getPostVar()][
"name"]);
196 $suffix = $filename_arr[
"extension"] ??
'';
197 $temp_name = $_FILES[$this->
getPostVar()][
"tmp_name"];
198 $error = $_FILES[$this->
getPostVar()][
"error"];
203 case UPLOAD_ERR_FORM_SIZE:
204 case UPLOAD_ERR_INI_SIZE:
205 $this->
setAlert($this->
lng->txt(
"form_msg_file_size_exceeds"));
208 case UPLOAD_ERR_PARTIAL:
209 $this->
setAlert($this->
lng->txt(
"form_msg_file_partially_uploaded"));
212 case UPLOAD_ERR_NO_FILE:
215 $this->
setAlert($this->
lng->txt(
"form_msg_file_no_upload"));
221 case UPLOAD_ERR_NO_TMP_DIR:
222 $this->
setAlert($this->
lng->txt(
"form_msg_file_missing_tmp_dir"));
225 case UPLOAD_ERR_CANT_WRITE:
226 $this->
setAlert($this->
lng->txt(
"form_msg_file_cannot_write_to_disk"));
229 case UPLOAD_ERR_EXTENSION:
230 $this->
setAlert($this->
lng->txt(
"form_msg_file_upload_stopped_ext"));
236 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
237 if (is_array($this->forbidden_suffixes) && in_array(strtolower($suffix), $this->forbidden_suffixes)) {
238 $this->
setAlert($this->
lng->txt(
"form_msg_file_type_is_not_allowed") .
" (" . $suffix .
")");
242 if (!in_array(strtolower($suffix), $this->
getSuffixes())) {
243 $this->
setAlert($this->
lng->txt(
"form_msg_file_wrong_file_type"));
250 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
252 if ($vir[0] ==
false) {
253 $this->
setAlert($this->
lng->txt(
"form_msg_file_virus_found") .
"<br />" . $vir[1]);
258 $file_name = $this->
str(
'file_name');
259 if ($file_name ===
"") {
260 $file_name = $_FILES[$this->
getPostVar()][
"name"];
272 public function render(
string $a_mode =
""): string
274 $quota_exceeded = $quota_legend =
false;
276 $f_tpl =
new ilTemplate(
"tpl.prop_file.html",
true,
true,
"Services/Form");
281 $f_tpl->setCurrentBlock(
'filename');
283 $f_tpl->setVariable(
'VAL_FILENAME', $this->
getFilename());
284 $f_tpl->setVariable(
'FILENAME_ID', $this->
getFieldId());
285 $f_tpl->setVariable(
'TXT_FILENAME_HINT', $this->
lng->txt(
'if_no_title_then_filename'));
286 $f_tpl->parseCurrentBlock();
288 if (trim($this->
getValue()) !=
"") {
290 $f_tpl->setCurrentBlock(
"delete_bl");
291 $f_tpl->setVariable(
"POST_VAR_D", $this->
getPostVar());
293 "TXT_DELETE_EXISTING",
294 $this->
lng->txt(
"delete_existing_file")
296 $f_tpl->parseCurrentBlock();
299 $f_tpl->setCurrentBlock(
'prop_file_propval');
300 $f_tpl->setVariable(
'FILE_VAL', $this->
getValue());
301 $f_tpl->parseCurrentBlock();
305 if ($a_mode !=
"toolbar") {
306 if (!$quota_exceeded) {
309 $f_tpl->setCurrentBlock(
"max_size");
310 $f_tpl->setVariable(
"TXT_MAX_SIZE", $this->
lng->txt(
"file_notice") .
" " .
312 $f_tpl->parseCurrentBlock();
315 $f_tpl->setVariable(
"TXT_MAX_SIZE",
true);
316 $f_tpl->parseCurrentBlock();
319 $f_tpl->setCurrentBlock(
"max_size");
320 $f_tpl->setVariable(
"TXT_MAX_SIZE", $quota_exceeded);
321 $f_tpl->parseCurrentBlock();
323 } elseif ($quota_exceeded) {
324 return $quota_exceeded;
329 $f_tpl->setCurrentBlock(
"pending");
330 $f_tpl->setVariable(
"TXT_PENDING", $this->
lng->txt(
"file_upload_pending") .
331 ": " . htmlentities($pending));
332 $f_tpl->parseCurrentBlock();
338 " disabled=\"disabled\"" 342 $f_tpl->setVariable(
'MAX_SIZE_WARNING', $this->
lng->txt(
'form_msg_file_size_exceeds'));
343 $f_tpl->setVariable(
'MAX_SIZE', $this->upload_limit->getPhpUploadLimitInBytes());
344 $f_tpl->setVariable(
"POST_VAR", $this->
getPostVar());
345 $f_tpl->setVariable(
"ID", $this->
getFieldId());
346 $f_tpl->setVariable(
"SIZE", $this->
getSize());
347 $f_tpl->setVariable(
"LABEL_SELECTED_FILES_INPUT", $this->
lng->txt(
'selected_files'));
351 $f_tpl->setVariable(
"TXT_BROWSE", $this->
lng->txt(
"select_file"));
354 return $f_tpl->get();
369 string $a_block =
"allowed_suffixes" 372 $suff_str = $delim =
"";
374 $suff_str .= $delim .
"." . $suffix;
379 "TXT_ALLOWED_SUFFIXES",
380 $this->
lng->txt(
"file_allowed_suffixes") .
" " . $suff_str
389 return sprintf(
"%.1f MB", $this->upload_limit->getPhpUploadLimitInBytes() / 1024 / 1024);
397 return (
int) ini_get(
"max_file_uploads");
402 if ($this->
int($this->
getPostVar() .
"_delete")) {
410 $html = $this->
render(
"toolbar");
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
Class IllegalStateException.
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)