I have a third-party PHP library that makes extensive use of realpath(). It works fine for subfolders, but fails for the site's root. Is there a fix (e.g. configuration change)? Or do I need to switch to a unix-based host in order for it to work as expected? It's part of a key component, so swapping out the realpath() calls isn't feasible.
Do you have any specific error messages? realpath() returns the same format regardless of where on the site it's working: Root: E:\web\username\htdocs\file.php Subfolder: E:\web\username\htdocs\subfolder\file.php So it should work the same everywhere. It does return 'false' if the realpath() value points to another directory though: realpath(/file.php) But the same value returns 'false' on linux too, so...not sure what the library is doing, but if you can point us to a page or a specific error maybe we can shed some light.
Sorry, to further clarify there's no error; as you mention it normally returns the path and if it can't it returns false (again, just for the root folder; no issues if its in a subfolder and called repeatedly). (edited, as I had a typo in example that was misleading) The following code sums it up: PHP: $path = dirname(__FILE__); echo "path: " . $path . "<br>"; $realpath = realpath($path); echo "realpath: " . $realpath. "<br>";
The above code on one of my sites (same behavior on two other Winhost-backed sites): http://wetzdev.com/test.php http://wetzdev.com/test/test.php
It could be an issue in the differences between the way Windows and *nix systems define "root," but from what I've had time to read I'm not sure how you might approach a workaround (since you're using - I assume - a third-party component). Have you asked the component's author if it's a known issue or if they have a solution?
In my searching I didn't find any general problem, which is why I posted here to begin with (I assumed it was an issue specific to Winhost's setup). If we have to switch to a unix host it's not the end of the world, just work I was hoping to avoid.
I did some research on this issue. For realpath to work, the anonymous user must have read permission for the entire directory hierarchy. I did a test in our dev environment and confirmed this to be the case. Your site is housed under e:\web directory We obviously cannot give all users read permission to the whole e:\ & e:\web directory as it will expose everyone's code. In my test $path = dirname(__FILE__) and realpath($path) returns the same exact result.
1. http://wetzdev.com/test.php 2. http://wetzdev.com/test/test.php path: E:\web\wetzdevc\test realpath: E:\web\wetzdevc\test no changes ....