Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Location
    New Hampshire
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Accessing files on network server with PHP

    How can I access files on a remote/network file server using PHP?

    I'm running an Apache server (v2.0.54) and PHP (v5.0.4) on a Win2K machine.

    I need to see if a file exists, but using file_exists('\\\Server\Share\Dir\test.txt'); always returns false for a file that does exist.

    I've also tried using the mapped letter in the path to no avail (e.g. 'G:\Dir\test.txt' - where "G:" is mapped to the "Share" dir on "Server").

    I added the full path and the mapped drive letter to the "include_path" line in the php.ini file as well but still nothing.

    I know for security reasons that this can be dangerous but this is only accessable by internal users so the security is not a big deal.

    The error messages I get in the Apache log are:
    PHP Warning: main() [<a href='function.include'>function.include</a>]: Failed opening 'test.txt' for inclusion (include_path='.;c:\\php\\includes;\\\\Server\\Share\\Dir\\;L:;L:\\') in C:\\Server\\Apache2\\htdocs\\Test\\remoteTest.php on line 14


    Help!!!

  • #2
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by oldhack
    I need to see if a file exists, but using file_exists('\\\Server\Share\Dir\test.txt');
    Just a long shot but why are you using \\\Server? That's not a windows network call path...\\Server\Share\Dir\test.txt however is (two \\ at the beginning rather than three)

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Location
    New Hampshire
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by weazel
    Just a long shot but why are you using \\\Server? That's not a windows network call path...\\Server\Share\Dir\test.txt however is (two \\ at the beginning rather than three)
    The "\" is the escape char in PHP so, if you only use two you really only get one in the string.

    Also, I actually escape the "\t" in the "\test.txt" by "\\test.txt" because the "\t" is interpreted as a (tab) I believe.

    I use echo $path; in the script prior to calling file_exists just to make sure I am getting a valid path (that's how I found that "\t" issue).

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by oldhack
    The "\" is the escape char in PHP so, if you only use two you really only get one in the string.

    Also, I actually escape the "\t" in the "\test.txt" by "\\test.txt" because the "\t" is interpreted as a (tab) I believe.

    I use echo $path; in the script prior to calling file_exists just to make sure I am getting a valid path (that's how I found that "\t" issue).
    This technique only applies where php is being evaluated using regexp.
    The line: file_exists('\\\Server\Share\Dir\test.txt');, the arguments are not being evaluated as php code, they are being evaluated as string data.
    However, you may have more problems with your include_path directive.

    include_path = ".;C:\Path\to\php\includes;L:\";

    This value can be set via ini, htaccess, httpd.conf or windows registry.
    This assumes that 'L' drive if your network shared files. Remember as well that with this code it will evalute from left to right, attempt to find file located in C:\Path\to\root\Server\Share\Dir\test.txt first from your document root, then from your C:\path\to\php\includes, and then from your L drive: L:\Server\Share\Dir\test.txt. Give that alteration a try, I haven't set up php to look across the network, but I see no reason why it shouldn't work.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •