Results 1 to 4 of 4

Thread: The first ever Jethro php question

  1. #1

    Thread Starter
    Junior Member Jethro's Avatar
    Join Date
    Oct 2002
    Location
    To the left of normality
    Posts
    31

    Thumbs up The first ever Jethro php question

    Ok have a text file "counter.txt" installed in the same directory as my .php script

    Here's the code that is being lame

    Code:
    $datafile = "/count.txt";
    $imgset = 3;
    $counter_digits = 6;
    
    $file = fopen($datafile, "r");
    It's erroring out on the fopen statement saying it can't locate the file ...... have also tried $datafile = "count.txt"

    Thanks in advance ....

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I responded at NX, but I'll respond here as well (different post though..)
    ....been having a problem since yesterday while trying to code a shoutbox. It was that i didnt know how to open a .txt, where all the entries would be stored, from different locations on the server (i.e. from root or from archive dir, etc).
    well, tried referring to the file to open on fopen using a http url, obviously doesnt work for a or w modes.
    So i, desperatley, tried referring to it using something like /usr/name/www/shout.txt, and to my surprise it worked, so i can call the .txt from anywhere on the site.
    heres part of the code:

    (note the {$HTTP_HOST}{$REQUEST_URI} on the form action so the post gets sent to the right place)

    <?
    $aqui = "http://{$HTTP_HOST}{$REQUEST_URI}";

    ?>

    <form action="<?print("$aqui");?>" method="post">

    <input class="inputbox2" type="text" name="sh" value="valor" size="20" maxlength="40">
    <input style="color: black; width: 10px; height: 17px;background-color: #aaaaaa; font-family: verdana, arial, helvetica, sans-serif;font-size: 10px;margin-top: 2px;width: 120px" type="submit" name="btrb" value="Adicionar">
    </form>

    <?

    $d = date("H:i-j/m/y");
    $fp = fopen ("/usr/home/pagon/www/shout.txt", "a");
    if (!($fp))
    {
    print ("ERROR file not open!");
    exit;
    }

    fputs($fp,"\n");
    fputs ($fp,"$d|$sh");
    fclose ($fp);

    }
    ?>

    just a bit of the code of my shoutbox, but you get the idea, it saved me quite a lot of work and i didnt find this documented anywhere, i thought i only had two choices: referer the file while on the same dir or use http, glad this works. :-)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    jethro, it's about time you come to the php side

    take the / off the file

    $datafile = "count.txt";
    $imgset = 3;
    $counter_digits = 6;

    $file = fopen($datafile, "r");



    if it is in the same directory you don't need it. fopen is very picky and if you use a path of any kind it is best to have it in a variable instead of in the fopen statement.

  4. #4

    Thread Starter
    Junior Member Jethro's Avatar
    Join Date
    Oct 2002
    Location
    To the left of normality
    Posts
    31
    Weird one ... wanted the full path not a relative one Chris fixed it up for me ... what a dude... next question coming up soon.
    See no sig

Posting Permissions

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



Click Here to Expand Forum to Full Width