jacobwb / hashover-next

This branch will be HashOver 2.0
GNU Affero General Public License v3.0
420 stars 87 forks source link

Wrong path when directory is symlink #256

Closed jcubic closed 5 years ago

jcubic commented 5 years ago

The code for calculating http_directory don't work on Linux (Fedora)

I've created simple file:

<?php

$root_directory = dirname (dirname (__DIR__));

// Get HTTP root directory
echo $_SERVER['DOCUMENT_ROOT'] . "\n";
$root_position = mb_strlen (realpath ($_SERVER['DOCUMENT_ROOT']));
$http_directory = mb_substr ($root_directory, $root_position);

header('Content-Type: text/plain');

print_r(array(
    "root_directory" => $root_directory,
    "root_position" => $root_position,
    "http_directory" => $http_directory
));

?>

and the output look like this:

/var/www/html
Array
(
    [root_directory] => /mnt/ssd/projects/jcubic/www
    [root_position] => 13
    [http_directory] => ects/jcubic/www
)

in my case I have symlink /var/www/html/projects -> /mnt/ssd/projects

I've fixed the issue by adding:

$http_directory = preg_replace("%/[^/]+/[^/]+$%", "", $_SERVER['REQUEST_URI']);

in settings.php