fopen problem, "w" does not work

Discussion in 'PHP' started by bosko, Nov 20, 2006.

  1. #1
    Hi!

    I'm new to php and I need help with my simple script:

    <?php
    $handle = fopen("bosko.txt", "r");
    $contents = "";
    while(!feof($handle)){
    $contents .= fread($handle, 1000);
    }
    fclose($handle);
    $firstrep = str_replace(" ", "", $contents);
    $newphrase = str_replace(",", " ", $firstrep);
    $fh = fopen("bosko.txt", "w");
    fwrite($fh, $newphrase);
    fclose($fh);
    ?>

    I want to open "bosko.txt", to modify it (this part is working) and then to write modified version back to file (this part is NOT working).
    All I get is:

    Warning: fopen(bosko.txt) [function.fopen]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\lilypond compiler\02.php on line 10

    Warning: fwrite(): supplied argument is not a valid stream resource in c:\Inetpub\wwwroot\lilypond compiler\02.php on line 11

    Warning: fclose(): supplied argument is not a valid stream resource in c:\Inetpub\wwwroot\lilypond compiler\02.php on line 12


    I'm running PHP 5, on localhost IIS 6, WinXP.

    Thanks in advance.

    Waiting for your help....

    Bosko
     
    bosko, Nov 20, 2006 IP
  2. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check if the file is writeable, ie. if the Read only flag is turned off.
     
    crazybjörn, Nov 20, 2006 IP
  3. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, it's turned off.
     
    bosko, Nov 20, 2006 IP
  4. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Go into the IIS manager thingy and then Permissions for the site(default site). Look for internet guest account, and make sure write box is ticked.

    At least I think that's how it worked, has been ages since I have looked at IIS.
     
    crazybjörn, Nov 20, 2006 IP
  5. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the tip but it didnt help. Also tryed with folder permissions, nothing again...
     
    bosko, Nov 20, 2006 IP
  6. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, I solved my problem with turning off simple sharing in folder view...
    Anyway, thanks for help.

    Bosko
     
    bosko, Nov 20, 2006 IP
  7. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Simple sharing? How strange, but then again when has IIS ever made sense :D
     
    crazybjörn, Nov 20, 2006 IP