Skip to content

Commit

Permalink
allow searching files in chroot options directories
Browse files Browse the repository at this point in the history
  • Loading branch information
eltharin committed Apr 22, 2024
1 parent a30da03 commit b773161
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Helpers.php
Expand Up @@ -59,7 +59,7 @@ public static function pre_r($mixed, $return = false)
* Vice versa, on using the local file system path of a file, make sure that the slash
* is appended (o.k. also for Windows)
*/
public static function build_url($protocol, $host, $base_path, $url)
public static function build_url($protocol, $host, $base_path, $url, $chrootDirs = [])
{
$protocol = mb_strtolower($protocol);
if (empty($protocol)) {
Expand Down Expand Up @@ -113,13 +113,26 @@ public static function build_url($protocol, $host, $base_path, $url)
$ret = preg_replace('/\?(.*)$/', "", $ret);

$filepath = realpath($ret);
if ($filepath === false) {
return null;
if ($filepath !== false) {
$ret = "$protocol$filepath$res";

return $ret;
}

$ret = "$protocol$filepath$res";
if ($url[0] == '/' && !empty($chrootDirs)) {
foreach ($chrootDirs as $dir) {
$ret = realpath($dir) . '/' . $url;
$ret = preg_replace('/\?(.*)$/', "", $ret);

if ($filepath = realpath($ret)) {
$ret = "$protocol$filepath$res";

return $ret;
return $ret;
}
}
}

return null;
}

$ret = $protocol;
Expand Down

0 comments on commit b773161

Please sign in to comment.