shlagish
04-29-2004, 10:52 PM
Hello,
I am using fopen("chat.txt","a").
at php.net (http://ca.php.net/fopen), they say that if the file doesn't exist, it will attempt to create it.
Well, when I try it out with a file that doesn't exist, I get the following message:
Warning: main(chat.txt): failed to open stream: No such file or directory in C:\Program Files\Abyss Web Server\htdocs\chat1.php on line 29
Fatal error: main(): Failed opening required 'chat.txt' (include_path='.;c:\php4\pear') in C:\Program Files\Abyss Web Server\htdocs\chat1.php on line 29
What am I doing wrong?
here is the complete code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Shawn Inder" />
<title>chat</title>
</head>
<body>
<?php
if(isset($_POST["sender"])){
echo("
<div>
<ul>
");
if(isset($_POST["message"])){
$fop = fopen("chat.txt","a");
$String = "<li>".$_POST["sender"].": ".$_POST["message"]."<li>\n";
flock($fop,LOCK_EX);
fputs($fop,$String);
fclose($fop);
}
require("chat.txt");
echo("
</ul>
<form action='".$_SERVER["PHP_SELF"]."' method='post'>
<input type='hidden' name='sender' value='".$_POST["sender"]."' />
<input type='text' name='message' />
<input type='submit' value='Send' />
</form>
</div>
");
}
else{
echo("
<form action='".$_SERVER["PHP_SELF"]."' method='post'>
<input type='text' name='sender' />
<input type='submit' value='Join the chat' />
</form>
");
}
?>
</body>
</html>
by the way, if you see anything stupid in my coding, please do tell me as I am new to PHP and havn't a clue on how to do a chat...
note: I don't expect it to add like a chat program just yet, it's far from done, but I have a question for the next step..
How do I make "chat.txt" be erased when there are no users left... or whatever a chat does...
Thanks for any help :)
I am using fopen("chat.txt","a").
at php.net (http://ca.php.net/fopen), they say that if the file doesn't exist, it will attempt to create it.
Well, when I try it out with a file that doesn't exist, I get the following message:
Warning: main(chat.txt): failed to open stream: No such file or directory in C:\Program Files\Abyss Web Server\htdocs\chat1.php on line 29
Fatal error: main(): Failed opening required 'chat.txt' (include_path='.;c:\php4\pear') in C:\Program Files\Abyss Web Server\htdocs\chat1.php on line 29
What am I doing wrong?
here is the complete code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Shawn Inder" />
<title>chat</title>
</head>
<body>
<?php
if(isset($_POST["sender"])){
echo("
<div>
<ul>
");
if(isset($_POST["message"])){
$fop = fopen("chat.txt","a");
$String = "<li>".$_POST["sender"].": ".$_POST["message"]."<li>\n";
flock($fop,LOCK_EX);
fputs($fop,$String);
fclose($fop);
}
require("chat.txt");
echo("
</ul>
<form action='".$_SERVER["PHP_SELF"]."' method='post'>
<input type='hidden' name='sender' value='".$_POST["sender"]."' />
<input type='text' name='message' />
<input type='submit' value='Send' />
</form>
</div>
");
}
else{
echo("
<form action='".$_SERVER["PHP_SELF"]."' method='post'>
<input type='text' name='sender' />
<input type='submit' value='Join the chat' />
</form>
");
}
?>
</body>
</html>
by the way, if you see anything stupid in my coding, please do tell me as I am new to PHP and havn't a clue on how to do a chat...
note: I don't expect it to add like a chat program just yet, it's far from done, but I have a question for the next step..
How do I make "chat.txt" be erased when there are no users left... or whatever a chat does...
Thanks for any help :)