19 declare(strict_types=1);
43 string $a_postvar =
"" 47 $this->
lng = $DIC->language();
48 $lng = $DIC->language();
49 $this->upload_service = $DIC->upload();
58 $value = $a_values[$this->
getPostVar()] ?? null;
59 if (!is_array($value)) {
69 public function setValue(
string $a_value): void
71 $this->value = $a_value;
79 public function setSize(
int $a_size): void
81 $this->size = $a_size;
92 $this->filename = $a_val;
102 $this->suffixes = $a_suffixes;
112 $this->forbidden_suffixes = $a_suffixes;
123 $this->pending = $a_val;
134 $this->filename_selection =
true;
135 $this->filename_post = $a_post_var;
150 $this->allow_deletion = $a_val;
160 if (!$this->upload_service->hasBeenProcessed()) {
162 $this->upload_service->process();
185 $utf_normal = $this->
refinery->string()->utfnormal()->formC();
186 $_FILES[$this->
getPostVar()][
"name"] = $utf_normal->transform(($_FILES[$this->
getPostVar()][
"name"]));
191 $filename = $_FILES[$this->
getPostVar()][
"name"];
192 $filename_arr = pathinfo($_FILES[$this->
getPostVar()][
"name"]);
193 $suffix = $filename_arr[
"extension"] ??
'';
194 $temp_name = $_FILES[$this->
getPostVar()][
"tmp_name"];
195 $error = $_FILES[$this->
getPostVar()][
"error"];
200 case UPLOAD_ERR_FORM_SIZE:
201 case UPLOAD_ERR_INI_SIZE:
205 case UPLOAD_ERR_PARTIAL:
209 case UPLOAD_ERR_NO_FILE:
218 case UPLOAD_ERR_NO_TMP_DIR:
222 case UPLOAD_ERR_CANT_WRITE:
226 case UPLOAD_ERR_EXTENSION:
233 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
234 if (is_array($this->forbidden_suffixes) && in_array(strtolower($suffix), $this->forbidden_suffixes)) {
235 $this->
setAlert(
$lng->
txt(
"form_msg_file_type_is_not_allowed") .
" (" . $suffix .
")");
239 if (!in_array(strtolower($suffix), $this->
getSuffixes())) {
247 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
249 if ($vir[0] ==
false) {
250 $this->
setAlert(
$lng->
txt(
"form_msg_file_virus_found") .
"<br />" . $vir[1]);
255 $file_name = $this->
str(
'file_name');
256 if ($file_name ===
"") {
257 $file_name = $_FILES[$this->
getPostVar()][
"name"];
269 public function render(
string $a_mode =
""): string
273 $quota_exceeded = $quota_legend =
false;
275 $f_tpl =
new ilTemplate(
"tpl.prop_file.html",
true,
true,
"Services/Form");
280 $f_tpl->setCurrentBlock(
'filename');
282 $f_tpl->setVariable(
'VAL_FILENAME', $this->
getFilename());
283 $f_tpl->setVariable(
'FILENAME_ID', $this->
getFieldId());
284 $f_tpl->setVariable(
'TXT_FILENAME_HINT',
$lng->
txt(
'if_no_title_then_filename'));
285 $f_tpl->parseCurrentBlock();
287 if (trim($this->
getValue()) !=
"") {
289 $f_tpl->setCurrentBlock(
"delete_bl");
290 $f_tpl->setVariable(
"POST_VAR_D", $this->
getPostVar());
292 "TXT_DELETE_EXISTING",
293 $lng->
txt(
"delete_existing_file")
295 $f_tpl->parseCurrentBlock();
298 $f_tpl->setCurrentBlock(
'prop_file_propval');
299 $f_tpl->setVariable(
'FILE_VAL', $this->
getValue());
300 $f_tpl->parseCurrentBlock();
304 if ($a_mode !=
"toolbar") {
305 if (!$quota_exceeded) {
308 $f_tpl->setCurrentBlock(
"max_size");
309 $f_tpl->setVariable(
"TXT_MAX_SIZE",
$lng->
txt(
"file_notice") .
" " .
311 $f_tpl->parseCurrentBlock();
314 $f_tpl->setVariable(
"TXT_MAX_SIZE",
true);
315 $f_tpl->parseCurrentBlock();
318 $f_tpl->setCurrentBlock(
"max_size");
319 $f_tpl->setVariable(
"TXT_MAX_SIZE", $quota_exceeded);
320 $f_tpl->parseCurrentBlock();
322 } elseif ($quota_exceeded) {
323 return $quota_exceeded;
328 $f_tpl->setCurrentBlock(
"pending");
329 $f_tpl->setVariable(
"TXT_PENDING",
$lng->
txt(
"file_upload_pending") .
330 ": " . htmlentities($pending));
331 $f_tpl->parseCurrentBlock();
337 " disabled=\"disabled\"" 341 $f_tpl->setVariable(
"POST_VAR", $this->
getPostVar());
342 $f_tpl->setVariable(
"ID", $this->
getFieldId());
343 $f_tpl->setVariable(
"SIZE", $this->
getSize());
347 $f_tpl->setVariable(
"TXT_BROWSE",
$lng->
txt(
"select_file"));
350 return $f_tpl->get();
365 string $a_block =
"allowed_suffixes" 370 $suff_str = $delim =
"";
372 $suff_str .= $delim .
"." . $suffix;
377 "TXT_ALLOWED_SUFFIXES",
378 $lng->
txt(
"file_allowed_suffixes") .
" " . $suff_str
387 $umf = ini_get(
"upload_max_filesize");
389 $pms = ini_get(
"post_max_size");
392 $multiplier_a = array(
"K" => 1024,
"M" => 1024 * 1024,
"G" => 1024 * 1024 * 1024);
394 $umf_parts = preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
395 $pms_parts = preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
397 if (count($umf_parts) == 2) {
398 $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
400 if (count($pms_parts) == 2) {
401 $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
405 $max_filesize = min($umf, $pms);
407 if (!$max_filesize) {
408 $max_filesize = max($umf, $pms);
412 $max_filesize = sprintf(
"%.1f MB", $max_filesize / 1024 / 1024);
414 return $max_filesize;
422 return (
int) ini_get(
"max_file_uploads");
427 if ($this->
int($this->
getPostVar() .
"_delete")) {
435 $html = $this->
render(
"toolbar");
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class IllegalStateException.
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)