Weird Troubles Writing to File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jolly Green Giant

    Weird Troubles Writing to File

    I'm trying to use PHP to create a text file. Simple right? I've done
    it before. I don't know why it's not working now. It's not rocket
    science. In general, I'd say I'm a PHP beginner, but with an
    intermediate skill level in certain facets of the language.

    $thisFileName = 'test.txt';
    $fp = fopen($thisFile Name, "w");
    $write = fputs($fp, "test");
    fclose($fp);
    if (!file_exists($ thisFileName))
    die("File does not exist.");

    * This script is in the same directory as the text file.
    * I am on a Windows server.
    * The permissions for the folder I'm in, and the files, is 666
    (read/write).
    * I have tried using just the file name and also the full path.

    I can modify that script to do a READ instead of a write, and set the
    filename to a file that exists already.... it works just fine. But
    even if I leave the filename to a file that exists, and try the above
    script to write over it... it won't work.

    How can I find out what the problem is? I'm not getting any PHP error
    info on browser. I guess they have debugging turned off.

    Thanks for any help!

    --
    JGG

  • tihu

    #2
    Re: Weird Troubles Writing to File


    Jolly Green Giant wrote:[color=blue]
    > I'm trying to use PHP to create a text file. Simple right? I've done
    > it before. I don't know why it's not working now. It's not rocket
    > science. In general, I'd say I'm a PHP beginner, but with an
    > intermediate skill level in certain facets of the language.
    >
    > $thisFileName = 'test.txt';
    > $fp = fopen($thisFile Name, "w");
    > $write = fputs($fp, "test");
    > fclose($fp);
    > if (!file_exists($ thisFileName))
    > die("File does not exist.");
    >
    > * This script is in the same directory as the text file.
    > * I am on a Windows server.
    > * The permissions for the folder I'm in, and the files, is 666
    > (read/write).
    > * I have tried using just the file name and also the full path.
    >
    > I can modify that script to do a READ instead of a write, and set the
    > filename to a file that exists already.... it works just fine. But
    > even if I leave the filename to a file that exists, and try the above
    > script to write over it... it won't work.
    >
    > How can I find out what the problem is? I'm not getting any PHP error
    > info on browser. I guess they have debugging turned off.
    >
    > Thanks for any help!
    >
    > --
    > JGG[/color]

    Sorry, not sure what the problem is.

    You should be able to turn error messages on with error_reporting (),
    use

    error_reporting (E_ALL);

    Another thing you could try is cut n paste the script in the php manual
    for fwrite (its identical to fputs) as it checks for errors after each
    step and it might tell you where the problem is.


    Seeya

    Tim

    Comment

    • Jolly Green Giant

      #3
      Re: Weird Troubles Writing to File

      Thank you! That error_reporting changed the debugging so that it told
      me that my file perms were wrong. Perfect. Thank you

      Comment

      Working...