PHP chmod file

Discussion in 'PHP' started by konkhra, Nov 19, 2005.

  1. #1
    Hello guys!

    I'm making a guestbook in php and it's working pretty well until it writes in a file on server.I'll post here the code that makes me crazy.

    I have declared this variables on my script:

    $fisier ="slay";
    $nrfisier=0;

    and the script with the problem is this:

    $f = fopen($fisier.$nrfisier.".usr", "at");

    if ( (!$f) || ((filesize($fisier.$nrfisier.".usr")>100000) ))
    {
    $nrfisier++;
    $f=fopen($fisier.$nrfisier.".usr","w");
    fwrite($f, sprintf("%s\t%s\t%s\r\n", $month,$day,$year));
    chmod ($fisier.$nrfisier.".usr",0777);
    }
    else
    {
    fwrite($f, sprintf("%s\t%s\t%s\r\n", $month, $day, $year));
    }
    fclose($f);
    chmod ($fisier.$nrfisier.".usr",0777);
    }
    }

    What I want to do is to write variables month day year in a file with the name slay01.usr and if this file is greater than 100k to write in another file slay02.usr and so on.For some reason this is not working on http server where is hosted my guestbook.Can you help me on this.Sorry that I've not posted all of my script but I think you'll understand me.Thank yo
     
    konkhra, Nov 19, 2005 IP
  2. luvkycool

    luvkycool Guest

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    keep in mind the filesize can only be checked of localfiles

    also i see the chmod command after writing to it,
    try to put it before the fwrite
     
    luvkycool, Nov 19, 2005 IP
  3. Michau

    Michau Well-Known Member

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Did you chmod the directory where you write the files, so that it is writable by the webserver? If not, it won't be apble fto create files in that directory.
     
    Michau, Dec 5, 2005 IP