Does anyone know if it is possible to use fopen to control a file across a network?

Basically I have written a script to randomly generate passwords on a monthly basis, I also want to save this script to a text file for reference.

My problem is that I am getting an error when trying to save to a file across the network, when I originally tested this locally there was no problem.

Here is the code I am using:

$entry_line = "$clients[$i] : $pass n";
$fp = fopen("Z:\Passwords\Passwords.txt", "a"); 
fputs($fp, $entry_line); 
fclose($fp); 

    I've had a bit more of a look on Php.net which advises to use double slashes e.g z:\passwords\passwords.txt however it is still falling over.

    Perhaps this is something to do with permissions, that I am unaware of?

      You cannot do fopen on network shares afaik, use the full name e.g.

      //computername/file

      Also PHP on Windows understands forward slashes in filenames so stick with them 🙂

        I'm still struggling with this! I was wondering if anyone can help me a little further.

        I did a quick IPconfig of the machine I am trying to call, and the machine I am trying to called is Server.

        Therefore the code I am using is:

        $fp = fopen("//Server/Passwords/Passwords.txt", "w"); // Clear the files contents
        fclose($fp);
        

        When I try and call this all I get is:

        Warning: fopen(//Server/Passwords/Passwords.txt): failed to open stream: No such file or directory in c:\development\password.php on line 17

        I have tried calling the machine by IP address, but I get jsut the same thing.

        Thinking about it the machine has two partitions C & D, and I can't see how calling it in this way would work, therefore I created a share on the machine (passwords), when I created this I ran the script and got the following error:

        Warning: fopen(//Server/Passwords/Passwords.txt): failed to open stream: Permission denied in c:\development\password.php on line 17

        This itself seems like a step in the right direction, but still doesn't help me out.

        Does anyone have any ideas? 😕

          Originally posted by furious5

          $fp = fopen("//Server/Passwords/Passwords.txt", "w"); // Clear the files contents
          fclose($fp);
          

          [/B]

          You should be opening that as "wb" or "wt" so that Windows understands that you're opening it as Binary or Text, which is what it likes, at least according to the PHP manual.

          That may solve the problem, otherwise this should work: Look in My Computer, view as Tiles (if you're using XP) and it should look something like in my attachement.

          That drive is on "\Usr01new\Vol1\SHARED" on my network, so that should tell you where to look.

          (from php manual)For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().

          Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead.

          kittfan2k

            Write a Reply...