PHP doesn't access root directory using forward slash "/"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ECRIA

    PHP doesn't access root directory using forward slash "/"

    Hi All,

    We are trying to figure out why PHP's file handling functions refuses to
    access the web root using the "/" character on our Windows machines. For
    example, a file /test.php is located in our web root. A file in a
    subdirectory, say /example/runme.php needs to find out if the file
    "/test.php" exists. One would expect that the function
    file_exists("/test.php") would return true (it does on our unix host).
    However, it returns false on our Windows machine.

    Unfortunately we can't build a workaround as it is not us but oscommerce
    that uses the "/" method to refer to the web root, and modifying all the
    oscommerce scripts is simply impractical.

    Any pointers would be greatly appreciated,

    Regards,

    ECRIA Dev. Team

    Details:
    Apache 2.0.52
    PHP 5.0.3
    Windows XP Pro SP2


  • Jay

    #2
    Re: PHP doesn't access root directory using forward slash "/"

    Hi

    On Windows this is not a valid Path "/test.php". If you want to test
    for a file aon the
    local directory use "./test.php" otherwise if you want to test for a
    file on your web root you should set a specific DOCUMENT ROOT depending
    on your webroot in apache. Then you could use

    if(file_exists( $_SERVER['DOCUMENT_ROOT']."/test.php"){
    echo "Yipee;
    }


    Good luck


    ECRIA schrieb:
    Hi All,
    >
    We are trying to figure out why PHP's file handling functions refuses to
    access the web root using the "/" character on our Windows machines. For
    example, a file /test.php is located in our web root. A file in a
    subdirectory, say /example/runme.php needs to find out if the file
    "/test.php" exists. One would expect that the function
    file_exists("/test.php") would return true (it does on our unix host).
    However, it returns false on our Windows machine.
    >
    Unfortunately we can't build a workaround as it is not us but oscommerce
    that uses the "/" method to refer to the web root, and modifying all the
    oscommerce scripts is simply impractical.
    >
    Any pointers would be greatly appreciated,
    >
    Regards,
    >
    ECRIA Dev. Team
    >
    Details:
    Apache 2.0.52
    PHP 5.0.3
    Windows XP Pro SP2

    Comment

    • Andy Hassall

      #3
      Re: PHP doesn't access root directory using forward slash "/"

      On Tue, 1 Aug 2006 07:57:43 -0400, "ECRIA" <php_file_probl em@ecria.comwro te:
      >We are trying to figure out why PHP's file handling functions refuses to
      >access the web root using the "/" character on our Windows machines. For
      >example, a file /test.php is located in our web root. A file in a
      >subdirectory , say /example/runme.php needs to find out if the file
      >"/test.php" exists. One would expect that the function
      >file_exists( "/test.php") would return true (it does on our unix host).
      >However, it returns false on our Windows machine.
      >
      >Unfortunatel y we can't build a workaround as it is not us but oscommerce
      >that uses the "/" method to refer to the web root, and modifying all the
      >oscommerce scripts is simply impractical.
      file_exists works in the filesystem space, not the URL space of the webserver.
      "/" never refers to the web root (unless your webserver was chroot'ed to the
      web root, which would be unusual); it's the filesystem root.

      On Windows this is further complicated because there are multiple roots, one
      per drive; "/" is a relative path on Windows, not an absolute path - relative
      to the drive of the current working directory.

      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      Working...