Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Shared :: "Linedancer 2/Unix Compliance.php"
- function UnixPathTrim($path) {
- $path = str_replace("\\", "/", $path);
- // Remove document root prefix if present
- if (strpos($path, $_SERVER['DOCUMENT_ROOT']) === 0) {
- $path = substr($path, strlen($_SERVER['DOCUMENT_ROOT']));
- }
- return $path;
- }
- function UnixPathSlashes($path) {
- $path = UnixPathTrim($path);
- $parts = explode("/", $path);
- $normalizedPath = $_SERVER['DOCUMENT_ROOT'];
- foreach ($parts as $part) {
- // Check if path is a directory
- if (glob($normalizedPath, GLOB_ONLYDIR)) {
- $normalizedPath .= "/{$part}";
- } elseif (glob($normalizedPath)) {
- $normalizedPath .= "/{$part}";
- break;
- }
- }
- return $normalizedPath;
- }
- function UnixPath($path) {
- $path = UnixPathSlashes($path);
- $path = UnixPathTrim($path);
- $parts = explode("/", $path);
- $normalizedPath = $_SERVER['DOCUMENT_ROOT'];
- foreach ($parts as $part) {
- $caseInsensitivePart = "";
- // Generate case-insensitive pattern
- for ($i = 0; $i < strlen($part); $i++) {
- $char = $part[$i];
- $caseInsensitivePart .= (strtolower($char) !== strtoupper($char)) ? "{" . strtolower($char) . "," . strtoupper($char) . "}" : $char;
- }
- // Apply glob with case-insensitive pattern
- $matchedDir = glob("{$normalizedPath}/{$caseInsensitivePart}", GLOB_ONLYDIR | GLOB_BRACE);
- $matchedFile = glob("{$normalizedPath}/{$caseInsensitivePart}", GLOB_BRACE);
- if ($matchedDir) {
- $normalizedPath .= "/{$part}";
- } elseif ($matchedFile) {
- $normalizedPath .= "/{$part}";
- break;
- }
- }
- return $normalizedPath;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement