2025-06-05 08:52:31 +02:00
|
|
|
|
<?php
|
2025-06-19 23:14:18 +02:00
|
|
|
|
// vfs.php
|
|
|
|
|
// Must sit in your project root (or adjust the require path below)
|
|
|
|
|
require_once __DIR__ . '/config.php';
|
2025-06-05 08:52:31 +02:00
|
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
|
/**
|
|
|
|
|
* Converts a virtual path ("/Documents/file.txt")
|
|
|
|
|
* into a real filesystem path under REAL_ROOT.
|
|
|
|
|
*/
|
2025-06-05 08:52:31 +02:00
|
|
|
|
function resolve_path(string $virtualPath): string {
|
2025-06-19 23:14:18 +02:00
|
|
|
|
// strip any “..” just in case
|
|
|
|
|
$virtualPath = str_replace('..', '', $virtualPath);
|
2025-06-05 08:52:31 +02:00
|
|
|
|
return rtrim(REAL_ROOT, '/') . '/' . ltrim($virtualPath, '/');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
|
/**
|
|
|
|
|
* Converts a real filesystem path back into a virtual one
|
|
|
|
|
* (so the front-end never sees your real server layout).
|
|
|
|
|
*/
|
2025-06-05 08:52:31 +02:00
|
|
|
|
function virtualize_path(string $realPath): string {
|
|
|
|
|
if (str_starts_with($realPath, REAL_ROOT)) {
|
|
|
|
|
return '/' . ltrim(substr($realPath, strlen(REAL_ROOT)), '/');
|
|
|
|
|
}
|
2025-06-19 23:14:18 +02:00
|
|
|
|
// fallback (shouldn’t happen if you always resolve under REAL_ROOT)
|
|
|
|
|
return $realPath;
|
|
|
|
|
}
|