ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclPropertyFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 public function keepTempFileUpload(
31 string $a_hash,
32 string $a_field,
33 string $a_tmp_name,
34 string $a_name,
35 string $a_type,
36 ?string $a_index = null,
37 ?string $a_sub_index = null
38 ): void {
39 $this->keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index, $a_sub_index);
40 }
41
42 public static function getTempFilename(
43 string $a_hash,
44 string $a_field,
45 string $a_name,
46 string $a_type,
47 ?string $a_index = null,
48 ?string $a_sub_index = null
49 ): string {
50 $a_name = ilFileUtils::getASCIIFilename($a_name);
51
52 $tmp_file_name = implode(
53 "~~",
54 [
55 session_id(),
56 $a_hash,
57 $a_field,
58 $a_index,
59 $a_sub_index,
60 str_replace("/", "~~", $a_type),
61 str_replace("~~", "_", $a_name),
62 ]
63 );
64
65 // make sure temp directory exists
66 $temp_path = ilFileUtils::getDataDir() . "/temp/";
67
68 return $temp_path . $tmp_file_name;
69 }
70
74 public static function rebuildTempFileByHash(string $hash): void
75 {
76 $temp_path = ilFileUtils::getDataDir() . "/temp";
77 if (is_dir($temp_path)) {
78 $temp_files = glob($temp_path . "/" . session_id() . "~~" . $hash . "~~*");
79 if (is_array($temp_files)) {
80 foreach ($temp_files as $full_file) {
81 $file = explode("~~", basename($full_file));
82 $field = $file[2];
83 $idx = $file[3];
84 $idx2 = $file[4];
85 $type = $file[5] . "/" . $file[6];
86 $name = $file[7];
87
88 if ($idx2 != "") {
89 if (!($_FILES[$field]["tmp_name"][$idx][$idx2] ?? false)) {
90 $_FILES[$field]["tmp_name"][$idx][$idx2] = $full_file;
91 $_FILES[$field]["name"][$idx][$idx2] = $name;
92 $_FILES[$field]["type"][$idx][$idx2] = $type;
93 $_FILES[$field]["error"][$idx][$idx2] = 0;
94 $_FILES[$field]["size"][$idx][$idx2] = filesize($full_file);
95 }
96 } else {
97 if ($idx != "") {
98 if (!($_FILES[$field]["tmp_name"][$idx] ?? false)) {
99 $_FILES[$field]["tmp_name"][$idx] = $full_file;
100 $_FILES[$field]["name"][$idx] = $name;
101 $_FILES[$field]["type"][$idx] = $type;
102 $_FILES[$field]["error"][$idx] = 0;
103 $_FILES[$field]["size"][$idx] = filesize($full_file);
104 }
105 } else {
106 if (!($_FILES[$field]["tmp_name"] ?? false)) {
107 $_FILES[$field]["tmp_name"] = $full_file;
108 $_FILES[$field]["name"] = $name;
109 $_FILES[$field]["type"] = $type;
110 $_FILES[$field]["error"] = 0;
111 $_FILES[$field]["size"] = filesize($full_file);
112 }
113 }
114 }
115 }
116 }
117 } else {
118 throw new ilDclException('temp dir path "' . $temp_path . '" is not a directory');
119 }
120 }
121
125 public function cleanupTempFiles(string $hash): void
126 {
127 $files = glob(ilFileUtils::getDataDir() . "/temp/" . session_id() . "~~" . $hash . "~~*");
128
129 foreach ($files as $file) {
130 if (file_exists($file)) {
131 unlink($file);
132 }
133 }
134 }
135}
Class ilDclPropertyFormGUI @ilCtrl_Calls ilDclPropertyFormGUI: ilFormPropertyDispatchGUI.
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.