Permalink
Browse files

Make directory check portable (#332)

* Make directory check portable

The current function did not work properly on Windows as there is a mismatch on slashes between what was returned by dirname and document_root.

* Fix ending slash

dirname is always a dir ending with slash while DOCUMENT_ROOT seems to avoid the last slash, so just adding + 1 to the substr should be enough to remove it.
  • Loading branch information...
friscoMad authored and Obihoernchen committed Dec 8, 2017
1 parent eca42d8 commit 51910d525c86b7e0a793572d948272a79c901ab0
Showing with 2 additions and 10 deletions.
  1. +2 −10 config.example.php
View
@@ -53,14 +53,6 @@
## Subdirectory trick
function directory()
{
$root = $_SERVER['DOCUMENT_ROOT'];
$filePath = dirname(__FILE__);
if ($root == $filePath) {
return ''; // installed in the root
} else {
$subdir_path = explode('/', $filePath);
$subdir = end($subdir_path);
return $subdir;
}
##https://stackoverflow.com/questions/2090723/how-to-get-the-relative-directory-no-matter-from-where-its-included-in-php
return substr(str_replace('\\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']))) + 1);
}

0 comments on commit 51910d5

Please sign in to comment.