ILIAS  release_8 Revision v8.24
class.ilDclPropertyFormGUI.php
Go to the documentation of this file.
1<?php
2
23{
27 public function keepTempFileUpload(
28 string $a_hash,
29 string $a_field,
30 string $a_tmp_name,
31 string $a_name,
32 string $a_type,
33 ?string $a_index = null,
34 ?string $a_sub_index = null
35 ): void {
36 $this->keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index, $a_sub_index);
37 }
38
39 public static function getTempFilename(
40 string $a_hash,
41 string $a_field,
42 string $a_name,
43 string $a_type,
44 ?string $a_index = null,
45 ?string $a_sub_index = null
46 ): string {
47 $a_name = ilFileUtils::getAsciiFileName($a_name);
48
49 $tmp_file_name = implode(
50 "~~",
51 array(
52 session_id(),
53 $a_hash,
54 $a_field,
55 $a_index,
56 $a_sub_index,
57 str_replace("/", "~~", $a_type),
58 str_replace("~~", "_", $a_name),
59 )
60 );
61
62 // make sure temp directory exists
63 $temp_path = ilFileUtils::getDataDir() . "/temp/";
64
65 return $temp_path . $tmp_file_name;
66 }
67
71 public static function rebuildTempFileByHash(string $hash): void
72 {
73 $temp_path = ilFileUtils::getDataDir() . "/temp";
74 if (is_dir($temp_path)) {
75 $temp_files = glob($temp_path . "/" . session_id() . "~~" . $hash . "~~*");
76 if (is_array($temp_files)) {
77 foreach ($temp_files as $full_file) {
78 $file = explode("~~", basename($full_file));
79 $field = $file[2];
80 $idx = $file[3];
81 $idx2 = $file[4];
82 $type = $file[5] . "/" . $file[6];
83 $name = $file[7];
84
85 if ($idx2 != "") {
86 if (!($_FILES[$field]["tmp_name"][$idx][$idx2] ?? false)) {
87 $_FILES[$field]["tmp_name"][$idx][$idx2] = $full_file;
88 $_FILES[$field]["name"][$idx][$idx2] = $name;
89 $_FILES[$field]["type"][$idx][$idx2] = $type;
90 $_FILES[$field]["error"][$idx][$idx2] = 0;
91 $_FILES[$field]["size"][$idx][$idx2] = filesize($full_file);
92 }
93 } else {
94 if ($idx != "") {
95 if (!($_FILES[$field]["tmp_name"][$idx] ?? false)) {
96 $_FILES[$field]["tmp_name"][$idx] = $full_file;
97 $_FILES[$field]["name"][$idx] = $name;
98 $_FILES[$field]["type"][$idx] = $type;
99 $_FILES[$field]["error"][$idx] = 0;
100 $_FILES[$field]["size"][$idx] = filesize($full_file);
101 }
102 } else {
103 if (!($_FILES[$field]["tmp_name"] ?? false)) {
104 $_FILES[$field]["tmp_name"] = $full_file;
105 $_FILES[$field]["name"] = $name;
106 $_FILES[$field]["type"] = $type;
107 $_FILES[$field]["error"] = 0;
108 $_FILES[$field]["size"] = filesize($full_file);
109 }
110 }
111 }
112 }
113 }
114 } else {
115 throw new ilDclException('temp dir path "' . $temp_path . '" is not a directory');
116 }
117 }
118
122 public function cleanupTempFiles(string $hash): void
123 {
124 $files = glob(ilFileUtils::getDataDir() . "/temp/" . session_id() . "~~" . $hash . "~~*");
125
126 foreach ($files as $file) {
127 if (file_exists($file)) {
128 unlink($file);
129 }
130 }
131 }
132}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static rebuildTempFileByHash(string $hash)
keepTempFileUpload(string $a_hash, string $a_field, string $a_tmp_name, string $a_name, string $a_type, ?string $a_index=null, ?string $a_sub_index=null)
Expose method for save confirmation.
cleanupTempFiles(string $hash)
Cleanup temp-files.
static getTempFilename(string $a_hash, string $a_field, string $a_name, string $a_type, ?string $a_index=null, ?string $a_sub_index=null)
Class ilFileUtils.
static getDataDir()
get data directory (outside webspace)
This class represents a property form user interface.
if($format !==null) $name
Definition: metadata.php:247
$type