Hello everyone,
I'm trying to write to a text file using php in my site. I have a php code that checks for raw post data and if there is data from the 'sender' value from input to fwrite (append) to file. It's basically a mini shoutbox created by me. It also reads the file and echos to screen. I added 1 line into the text file just to make sure the echo works and it does.
My problem seems to be in the writing. Here is my current code.
Perhaps the site does not allow php to write to text file, which by the way does have world write ability.
I will be making this so it ends up reading only that last 8-10 lines eventually, but first to get it working.
Thanks in advance.
I'm trying to write to a text file using php in my site. I have a php code that checks for raw post data and if there is data from the 'sender' value from input to fwrite (append) to file. It's basically a mini shoutbox created by me. It also reads the file and echos to screen. I added 1 line into the text file just to make sure the echo works and it does.
My problem seems to be in the writing. Here is my current code.
Code:
<?php
$self = $_SERVER['PHP_SELF'];
$ipaddress = ("$_SERVER[REMOTE_ADDR]");
if(isset($_POST['send'])) {
if(empty($_POST['shtAuthor1']) || empty($_POST['limitedtextarea'])) {
echo('<p>You did not fill in a required field.</p>');
}
else {
if (file_exists("shouts.txt")) {
$name = htmlspecialchars($_POST['shtAuthor1']);
$post = htmlspecialchars($_POST['limitedtextarea']);
$fh = fopen("shouts.txt", 'a');
fwrite($fh, $post."<br/>\n") or die("Write Failed POST");
fwrite($fh, $name."<br/>\n") or die("Write Failed NAME");
fclose($fh);
echo ('<p>Thanks for Shouting</p>');
}
else {
echo ('<p>Cannot load File</p>');
}
}
}
else
{
}
?>
<div id="shoutbox">
<ul><?php
$fh = fopen("shouts.txt", 'r');
$posts = fread($fh, 40);
$names = fread($fh, 19);
echo ("<p>$posts</P>");
echo ("<p>$names</p>");
?>
</ul>
// 2 textareas here...
<input type = "submit" value="send">
</div>
Perhaps the site does not allow php to write to text file, which by the way does have world write ability.
I will be making this so it ends up reading only that last 8-10 lines eventually, but first to get it working.
Thanks in advance.
Last edited: