note 21026 added to function.fopen
| From: | me at pagongski dot com | Date: | Thu, 25 Apr 2002 15:57:44 +0000 |
| Subject: | note 21026 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29842@lists.php.net to get a copy of this message | ||
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. :-)
--
http://www.php.net/manual/en/function.fopen.php
http://master.php.net/manage/user-notes.php?action=edit+21026
http://master.php.net/manage/user-notes.php?action=delete+21026
http://master.php.net/manage/user-notes.php?action=reject+21026