Jump to content

[SOLVED] fwrite


Andy-H

Recommended Posts

Hello all, I am trying to teach myself the uses of fopen, fread and fwrite by writing a simple PHP/AJAX chat that writes and reads messages to and from a text file, I was just wondering what data needs to be escaped when using fwrite() and if there is a specific function to do this.

 

Thanks for all/any replys.

Link to comment
Share on other sites

Warning: fopen(chat.txt) [function.fopen]: failed to open stream: Permission denied in /home/mafiaworld/domains/mafia-world.net/public_html/andy/chat.php on line 11

 

Does that mean fopen has been disabled?

Link to comment
Share on other sites

I have come across another problem, when I write the data to the file it overwrites the last part that was added, how can I make it add to the content of the file rather than overwrite it?

 

My current code is:

 

<?php
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
session_start();
$user = $_SESSION['user'];
$msg  = htmlentities($_GET['entry'], ENT_QUOTES);
$file = 'chat.txt';
$f = fopen($file, 'w');
$str = '<tr><td width="75" align="left"> ' . $user . '</td><td width="125" align="left"> ' . date("d-m-y g:ia") . '</td><td width="650" align="left"> ' . $msg . '</td></tr>';
fwrite($f, $str);
fclose($f);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.