19 declare(strict_types=1);
47 string $a_postvar =
"" 51 $this->
lng = $DIC->language();
52 $this->
lng->loadLanguageModule(
'form');
54 $this->upload_service = $DIC->upload();
55 $this->upload_limit = $DIC[
'ui.upload_limit_resolver'];
65 if (!is_array($value)) {
75 public function setValue(
string $a_value): void
77 $this->value = $a_value;
85 public function setSize(
int $a_size): void
87 $this->size = $a_size;
98 $this->filename = $a_val;
108 $this->suffixes = $a_suffixes;
118 $this->forbidden_suffixes = $a_suffixes;
129 $this->pending = $a_val;
140 $this->filename_selection =
true;
141 $this->filename_post = $a_post_var;
156 $this->allow_deletion = $a_val;
166 if (!$this->upload_service->hasBeenProcessed()) {
168 $this->upload_service->process();
183 $this->
setAlert($this->
lng->txt(
"form_msg_file_size_exceeds"));
189 $utf_normal = $this->
refinery->string()->utfnormal()->formC();
190 $_FILES[$this->
getPostVar()][
"name"] = $utf_normal->transform(($_FILES[$this->
getPostVar()][
"name"]));
195 $filename = $_FILES[$this->
getPostVar()][
"name"];
196 $filename_arr = pathinfo($_FILES[$this->
getPostVar()][
"name"]);
197 $suffix = $filename_arr[
"extension"] ??
'';
198 $temp_name = $_FILES[$this->
getPostVar()][
"tmp_name"];
199 $error = $_FILES[$this->
getPostVar()][
"error"];
204 case UPLOAD_ERR_FORM_SIZE:
205 case UPLOAD_ERR_INI_SIZE:
206 $this->
setAlert($this->
lng->txt(
"form_msg_file_size_exceeds"));
209 case UPLOAD_ERR_PARTIAL:
210 $this->
setAlert($this->
lng->txt(
"form_msg_file_partially_uploaded"));
213 case UPLOAD_ERR_NO_FILE:
216 $this->
setAlert($this->
lng->txt(
"form_msg_file_no_upload"));
222 case UPLOAD_ERR_NO_TMP_DIR:
223 $this->
setAlert($this->
lng->txt(
"form_msg_file_missing_tmp_dir"));
226 case UPLOAD_ERR_CANT_WRITE:
227 $this->
setAlert($this->
lng->txt(
"form_msg_file_cannot_write_to_disk"));
230 case UPLOAD_ERR_EXTENSION:
231 $this->
setAlert($this->
lng->txt(
"form_msg_file_upload_stopped_ext"));
237 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
238 if (is_array($this->forbidden_suffixes) && in_array(strtolower($suffix), $this->forbidden_suffixes)) {
239 $this->
setAlert($this->
lng->txt(
"form_msg_file_type_is_not_allowed") .
" (" . $suffix .
")");
243 if (!in_array(strtolower($suffix), $this->
getSuffixes())) {
244 $this->
setAlert($this->
lng->txt(
"form_msg_file_wrong_file_type"));
251 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"") {
253 if ($vir[0] ==
false) {
254 $this->
setAlert($this->
lng->txt(
"form_msg_file_virus_found") .
"<br />" . $vir[1]);
259 $file_name = $this->
str(
'file_name');
260 if ($file_name ===
"") {
261 $file_name = $_FILES[$this->
getPostVar()][
"name"];
273 public function render(
string $a_mode =
""): string
275 $quota_exceeded = $quota_legend =
false;
277 $f_tpl =
new ilTemplate(
"tpl.prop_file.html",
true,
true,
"components/ILIAS/Form");
282 $f_tpl->setCurrentBlock(
'filename');
284 $f_tpl->setVariable(
'VAL_FILENAME', $this->
getFilename());
285 $f_tpl->setVariable(
'FILENAME_ID', $this->
getFieldId());
286 $f_tpl->setVariable(
'TXT_FILENAME_HINT', $this->
lng->txt(
'if_no_title_then_filename'));
287 $f_tpl->parseCurrentBlock();
289 if (trim($this->
getValue()) !=
"") {
291 $f_tpl->setCurrentBlock(
"delete_bl");
292 $f_tpl->setVariable(
"POST_VAR_D", $this->
getPostVar());
294 "TXT_DELETE_EXISTING",
295 $this->
lng->txt(
"delete_existing_file")
297 $f_tpl->parseCurrentBlock();
300 $f_tpl->setCurrentBlock(
'prop_file_propval');
301 $f_tpl->setVariable(
'FILE_VAL', $this->
getValue());
302 $f_tpl->parseCurrentBlock();
306 if ($a_mode !=
"toolbar") {
307 if (!$quota_exceeded) {
310 $f_tpl->setCurrentBlock(
"max_size");
311 $f_tpl->setVariable(
"TXT_MAX_SIZE", $this->
lng->txt(
"file_notice") .
" " .
313 $f_tpl->parseCurrentBlock();
316 $f_tpl->setVariable(
"TXT_MAX_SIZE",
true);
317 $f_tpl->parseCurrentBlock();
320 $f_tpl->setCurrentBlock(
"max_size");
321 $f_tpl->setVariable(
"TXT_MAX_SIZE", $quota_exceeded);
322 $f_tpl->parseCurrentBlock();
324 } elseif ($quota_exceeded) {
325 return $quota_exceeded;
330 $f_tpl->setCurrentBlock(
"pending");
331 $f_tpl->setVariable(
"TXT_PENDING", $this->
lng->txt(
"file_upload_pending") .
332 ": " . htmlentities($pending));
333 $f_tpl->parseCurrentBlock();
339 " disabled=\"disabled\"" 343 $f_tpl->setVariable(
'MAX_SIZE_WARNING', $this->
lng->txt(
'form_msg_file_size_exceeds'));
344 $f_tpl->setVariable(
'MAX_SIZE', $this->upload_limit->getPhpUploadLimitInBytes());
345 $f_tpl->setVariable(
"POST_VAR", $this->
getPostVar());
346 $f_tpl->setVariable(
"ID", $this->
getFieldId());
347 $f_tpl->setVariable(
"SIZE", $this->
getSize());
348 $f_tpl->setVariable(
"LABEL_SELECTED_FILES_INPUT", $this->
lng->txt(
'selected_files'));
352 $f_tpl->setVariable(
"TXT_BROWSE", $this->
lng->txt(
"select_file"));
355 return $f_tpl->get();
370 string $a_block =
"allowed_suffixes" 373 $suff_str = $delim =
"";
375 $suff_str .= $delim .
"." . $suffix;
380 "TXT_ALLOWED_SUFFIXES",
381 $this->
lng->txt(
"file_allowed_suffixes") .
" " . $suff_str
390 return sprintf(
"%.1f MB", $this->upload_limit->getPhpUploadLimitInBytes() / 1024 / 1024);
398 return (
int) ini_get(
"max_file_uploads");
403 if ($this->
int($this->
getPostVar() .
"_delete")) {
411 $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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)