Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

live editing of files.

Status
Not open for further replies.

cleansedbb

Technical User
Joined
Feb 11, 2002
Messages
95
Location
US
I've got the following and it lets me view the file test.log and whatever I type gets appended to the bottom. what I want to be able to do is also remove from the file.

the files contents are:

test
1.1.1.1
hello
blah
blah blah blah

I want to say remove hello. it will be random. the text shows up in a textarea so you can type/delete but on submit it doesnt write anything but the new stuff to the bottom of the file.



CODE:

<?
if (! ($submit))
{
?>
<html>
<body>
<form action=&quot;./test.php&quot; method=post>
<textarea name=list cols=45 rows=15><?php include &quot;./test.log&quot;; ?></textarea>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
<?
}
else
{
$write = $list;
$fp = fopen(&quot;visitor.log&quot;,&quot;a&quot;);
fwrite($fp,$write);
fclose($fp);
}
?>

</form>
</body>
</html>
 
The only way to randomly remove data from a text file is to open a new file, read from the old file, and write that data with changes to the new file.

However, with a live logfile, this is difficult without using file locking. But that means that whatever app that is writing to that log must be aware of file locks, too.

flock() (
Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top