3namespace Bitrix\Main\IO;
30 static $pattern =
null, $tailPattern;
33 if (strncasecmp(PHP_OS,
"WIN", 3) == 0)
37 $tailPattern =
"\0.\\/+ ";
48 if (str_contains($pathTmp,
"\0"))
53 if (preg_match(
"#(^|/)(\\.|\\.\\.)(/|\$)#", $pathTmp))
55 $pathTmpParts = explode(
'/', $pathTmp);
57 foreach ($pathTmpParts as $pathPart)
59 if ($pathPart ===
'.')
64 if ($pathPart ===
"..")
66 if (array_pop($pathStack) ===
null)
73 $pathStack[] = $pathPart;
76 $pathTmp = implode(
"/", $pathStack);
79 $pathTmp = rtrim($pathTmp, $tailPattern);
81 if (str_starts_with(
$path,
"/") && !str_starts_with($pathTmp,
"/"))
83 $pathTmp =
"/" . $pathTmp;
102 return mb_substr(
$path, $pos + 1);
113 return mb_substr(
$path,
$p + 1);
121 return mb_substr(
$path, 0, -mb_strlen(self::getName(
$path)) - 1);
126 if (self::$physicalEncoding ==
'')
131 if (self::$logicalEncoding ==
'')
136 if (self::$physicalEncoding == self::$logicalEncoding)
146 if (self::$physicalEncoding ==
'')
151 if (self::$logicalEncoding ==
'')
156 if (self::$physicalEncoding == self::$logicalEncoding)
166 if (self::$logicalEncoding ==
'')
173 if (
'utf-8' !== self::$logicalEncoding)
178 return implode(
'/', array_map(
"rawurlencode", explode(
'/',
$path)));
183 if (self::$physicalEncoding ==
'')
190 if (
'utf-8' !== self::$physicalEncoding)
195 return implode(
'/', array_map(
"rawurlencode", explode(
'/',
$path)));
200 static $directoryIndex =
null;
202 if ($directoryIndex ===
null)
207 if (isset($directoryIndex[self::getName(
$path)]))
217 if (self::$physicalEncoding ==
'')
222 $path = implode(
'/', array_map(
"rawurldecode", explode(
'/',
$path)));
224 if (
'utf-8' !== self::$physicalEncoding)
239 $physicalEncoding = defined(
"BX_FILE_SYSTEM_ENCODING") ? BX_FILE_SYSTEM_ENCODING :
'';
242 if (strtoupper(substr(PHP_OS, 0, 3)) ===
"WIN")
257 foreach ($args as $arg)
263 if (is_string($v) && $v !=
'')
269 elseif (is_string($arg) && $arg !=
'')
277 $result = implode(self::DIRECTORY_SEPARATOR, $parts);
288 if (!is_string($relativePath))
292 if ($relativePath ==
'')
302 if (!is_string($relativePath) || $relativePath ==
'')
314 if (!is_string(
$path))
319 if (trim(
$path) ==
'')
324 if (str_contains(
$path,
"\0"))
329 if (preg_match(
"#(" . self::INVALID_FILENAME_BYTES .
")#",
$path))
339 if (!static::validateCommon(
$path))
344 return (preg_match(
"#^([a-z]:)?/([^\x01-\x1F" . preg_quote(self::INVALID_FILENAME_CHARS,
"#") .
"]+/?)*$#isD",
$path) > 0);
354 return (preg_match(
"#^[^\x01-\x1F" . preg_quote(self::INVALID_FILENAME_CHARS,
"#") .
"]+$#isD",
$filename) > 0);
364 return preg_replace_callback(
365 "#([\x01-\x1F" . preg_quote(self::INVALID_FILENAME_CHARS,
"#") .
"]|" . self::INVALID_FILENAME_BYTES .
")#",
377 return static::replaceInvalidFilename(
$filename,
379 return chr(rand(97, 122));
386 return (str_starts_with(
$path,
"/")) || preg_match(
"#^[a-z]:/#i",
$path);
391 static $directoryIndexDefault = [
"index.php" => 1,
"index.html" => 1,
"index.htm" => 1,
"index.phtml" => 1,
"default.html" => 1,
"index.php3" => 1];
394 if ($directoryIndex !==
null)
396 return $directoryIndex;
399 return $directoryIndexDefault;
static convertUriToPhysical($path)
static convertPhysicalToLogical($path)
static randomizeInvalidFilename($filename)
static validateCommon($path)
static getLogicalEncoding()
static convertRelativeToAbsolute($relativePath)
const DIRECTORY_SEPARATOR
static convertPhysicalToUri($path)
static getPhysicalEncoding()
static convertLogicalToPhysical($path)
static convertLogicalToUri($path)
static combine(... $args)
static convertSiteRelativeToAbsolute($relativePath, $site=null)
static getDirectory($path)
const INVALID_FILENAME_BYTES
static getExtension($path)
static validateFilename($filename)
const INVALID_FILENAME_CHARS
static getDirectoryIndexArray()
static truncateIndexFile($path)
static replaceInvalidFilename($filename, $callback)
static getDocumentRoot($siteId=null)
static convertEncoding($data, $charsetFrom, $charsetTo)
static getLastPosition($haystack, $needle)
$_SERVER["DOCUMENT_ROOT"]
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(!Loader::includeModule('sale')) $pattern