Worth2Read
Home

Forum

PHP Tutorials
Blogs
Children
Article Directory

Contact Us

Disclaimer
Reliable $1 Web Hosting by 3iX
 

If you have any doubts with your PHP code please discuss it in the PHP Forum

PHP Script to keep a .txt document at the server and update it remotely

People usually keeps important data in computer. It will be easier if they can retrieve it from any computer .

A solution for this is keep the .txt document in the server.

Access it from the server , update it according to the way they want and save it there.

PHP script for doing this is as follows...

<?php
echo '<center>';
if(isset($_POST['submit']))
{
echo '<table bgcolor="#efefef" width="500"><tr><td>';
echo stripslashes($_POST['stuff']);
echo '</td></tr></table>';
$fd=fopen("welcome.txt","w");
fwrite($fd, $_POST['stuff']);
fclose($fd);

}
echo '<br><br><form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo '<textarea name="stuff" cols="60" rows="10">';
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);

echo '</textarea><br>';
echo '<input type="submit" name="submit" value="Update File"></center>';
?>

Display the numberr of lines in a .txt file

The following code will display the number of lines in a .txt file.

<?php
$file = "welcome.txt";
$lines = count(file($file));
echo "There are $lines lines in $file";
?>

A demo of the above script can be seen at

http://www.worth2read.org/test/notepad_script.php


Copyright © 2008 www.worth2read.org. All rights Reserved. Use of this Site is subject to our Privacy Statement

Untitled Document