4 include_once
'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
5 include_once(
"./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
57 $this->value = $a_value;
77 $this->size = $a_size;
97 $this->filename = $a_val;
119 $this->suffixes = $a_suffixes;
129 return $this->suffixes;
139 $this->pending = $a_val;
161 $this->filename_selection =
true;
162 $this->filename_post = $a_post_var;
173 return $this->filename_selection ?
true :
false;
200 while (substr($_FILES[$this->
getPostVar()][
"name"],-1) ==
'/')
206 $filename_arr = pathinfo($_FILES[$this->
getPostVar()][
"name"]);
207 $suffix = $filename_arr[
"extension"];
208 $mimetype = $_FILES[$this->
getPostVar()][
"type"];
209 $size_bytes = $_FILES[$this->
getPostVar()][
"size"];
210 $temp_name = $_FILES[$this->
getPostVar()][
"tmp_name"];
211 $error = $_FILES[$this->
getPostVar()][
"error"];
218 $this->
setAlert($lng->txt(
"form_msg_file_size_exceeds"));
227 case UPLOAD_ERR_INI_SIZE:
228 $this->
setAlert($lng->txt(
"form_msg_file_size_exceeds"));
232 case UPLOAD_ERR_FORM_SIZE:
233 $this->
setAlert($lng->txt(
"form_msg_file_size_exceeds"));
237 case UPLOAD_ERR_PARTIAL:
238 $this->
setAlert($lng->txt(
"form_msg_file_partially_uploaded"));
242 case UPLOAD_ERR_NO_FILE:
247 $this->
setAlert($lng->txt(
"form_msg_file_no_upload"));
253 case UPLOAD_ERR_NO_TMP_DIR:
254 $this->
setAlert($lng->txt(
"form_msg_file_missing_tmp_dir"));
258 case UPLOAD_ERR_CANT_WRITE:
259 $this->
setAlert($lng->txt(
"form_msg_file_cannot_write_to_disk"));
263 case UPLOAD_ERR_EXTENSION:
264 $this->
setAlert($lng->txt(
"form_msg_file_upload_stopped_ext"));
271 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"" &&
274 if (!in_array(strtolower($suffix), $this->
getSuffixes()))
276 $this->
setAlert($lng->txt(
"form_msg_file_wrong_file_type"));
282 if ($_FILES[$this->
getPostVar()][
"tmp_name"] !=
"")
285 if ($vir[0] ==
false)
287 $this->
setAlert($lng->txt(
"form_msg_file_virus_found").
"<br />".$vir[1]);
302 $f_tpl =
new ilTemplate(
"tpl.prop_file.html",
true,
true,
"Services/Form");
308 $f_tpl->setCurrentBlock(
'filename');
310 $f_tpl->setVariable(
'VAL_FILENAME',$this->
getFilename());
311 $f_tpl->setVariable(
'FILENAME_ID',$this->
getFieldId());
312 $f_tpl->setVAriable(
'TXT_FILENAME_HINT',$lng->txt(
'if_no_title_then_filename'));
313 $f_tpl->parseCurrentBlock();
319 $f_tpl->setCurrentBlock(
'prop_file_propval');
320 $f_tpl->setVariable(
'FILE_VAL', $this->
getValue());
321 $f_tpl->parseCurrentBlock();
325 if ($a_mode !=
"toolbar")
329 $f_tpl->setCurrentBlock(
"max_size");
330 $f_tpl->setVariable(
"TXT_MAX_SIZE", $lng->txt(
"file_notice").
" ".
332 $f_tpl->parseCurrentBlock();
338 $f_tpl->setCurrentBlock(
"pending");
339 $f_tpl->setVariable(
"TXT_PENDING", $lng->txt(
"file_upload_pending").
341 $f_tpl->parseCurrentBlock();
344 $f_tpl->setVariable(
"POST_VAR", $this->
getPostVar());
345 $f_tpl->setVariable(
"ID", $this->
getFieldId());
346 $f_tpl->setVariable(
"SIZE", $this->
getSize());
348 return $f_tpl->get();
360 $a_tpl->setCurrentBlock(
"prop_generic");
361 $a_tpl->setVariable(
"PROP_GENERIC", $html);
362 $a_tpl->parseCurrentBlock();
372 $suff_str = $delim =
"";
375 $suff_str.= $delim.
".".$suffix;
378 $a_tpl->setCurrentBlock($a_block);
379 $a_tpl->setVariable(
"TXT_ALLOWED_SUFFIXES",
380 $lng->txt(
"file_allowed_suffixes").
" ".$suff_str);
381 $a_tpl->parseCurrentBlock();
388 $umf = ini_get(
"upload_max_filesize");
390 $pms = ini_get(
"post_max_size");
393 $multiplier_a=array(
"K"=>1024,
"M"=>1024*1024,
"G"=>1024*1024*1024);
395 $umf_parts=preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
396 $pms_parts=preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
398 if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
399 if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
402 $max_filesize = min($umf, $pms);
404 if (!$max_filesize) $max_filesize=max($umf, $pms);
407 $max_filesize = sprintf(
"%.1f MB",$max_filesize/1024/1024);
409 return $max_filesize;
417 $html = $this->
render(
"toolbar");