31 $dir_name = self::GetAbsoluteRoot();
32 $file_name = rel2abs(
"/",
"/" . $file_name);
38 $temp_path = $dir_name .
"/" . $dir_add . $file_name;
40 if (!file_exists($temp_path))
43 if (!self::$is_exit_function_registered)
45 self::$is_exit_function_registered =
true;
46 register_shutdown_function([
'CTempFile',
'Cleanup']);
49 self::$arFiles[$temp_path] = $dir_name .
"/" . $dir_add;
59 if ($hours_to_keep_files <= 0)
67 $dir_name = self::GetAbsoluteRoot() .
'/BXTEMP-' . date(
'Y-m-d/H/', time() + 3600 * $hours_to_keep_files);
71 $temp_path = $dir_name . $dir_add .
"/";
73 if (!file_exists($temp_path))
82 if (!isset($localStorage[
'tempFileToken']))
86 $token = $localStorage->get(
'tempFileToken');
88 $subdir = implode(
"/", (is_array($subdir) ? $subdir : [$subdir, $token])) .
"/";
89 while (str_contains($subdir,
"//"))
91 $subdir = str_replace(
"//",
"/", $subdir);
94 for (
$i = $hours_to_keep_files - 1;
$i > 0;
$i--)
96 $dir_name = self::GetAbsoluteRoot() .
'/BXTEMP-' . date(
'Y-m-d/H/', time() + 3600 *
$i);
97 $temp_path = $dir_name . $subdir;
98 if (file_exists($temp_path) && is_dir($temp_path))
107 $dir_name = self::GetAbsoluteRoot() .
'/BXTEMP-' . date(
'Y-m-d/H/', time() + 3600 * $hours_to_keep_files);
108 $temp_path = $dir_name . $subdir;
113 if (!self::$is_exit_function_registered)
115 self::$is_exit_function_registered =
true;
116 register_shutdown_function([
'CTempFile',
'Cleanup']);
126 foreach (self::$arFiles as $temp_path => $temp_dir)
128 if (file_exists($temp_path))
131 if (is_file($temp_path))
138 str_ends_with($temp_path,
'/')
139 && !str_contains($temp_path,
"BXTEMP")
140 && is_dir($temp_path)
143 CTempFile::_absolute_path_recursive_delete($temp_path);
146 elseif (file_exists($temp_dir))
153 $dir_name = self::GetAbsoluteRoot() .
"/";
154 if (file_exists($dir_name))
156 if (
$handle = opendir($dir_name))
158 while (($day_files_dir = readdir(
$handle)) !==
false)
160 if ($day_files_dir ==
'.' || $day_files_dir ==
'..')
164 if (preg_match(
"/^BXTEMP-(.*?)\$/", $day_files_dir) && is_dir($dir_name . $day_files_dir))
166 CTempFile::_process_directory($dir_name, $day_files_dir);