PHP realpath failing on site root

Discussion in 'Site Programming, Development and Design' started by Peter Wetzel, Nov 29, 2013.

  1. 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.
  2. 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.
  3. 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:

        $path dirname(__FILE__);
    "path: " $path "<br>";
    $realpath realpath($path);
    "realpath: " $realpath"<br>";
  4. Last edited by a moderator: Oct 14, 2015
  5. 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?
  6. 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.
    Last edited by a moderator: Oct 14, 2015
  7. I just tested on a local IIS (v7.5) install and realpath seems to work fine at root.
  8. FredC

    FredC Winhost Staff

    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__)



    returns the same exact result.
    ComputerMan and Michael like this.
  9. Ug, too bad. Thanks for the help.
  10. Yep, the root one still fails. We had to switch to a linux-based host for the real app.

Share This Page