Writing In A File Via PHP – Tutorial and Script Download

by Hiroshi on June 16, 2008

in File, File Manipulation

This system allows you to write some data in a simple text file and saving it through php. It contains a form which asks from user his name, email and than onsubmit this script writes these information along with his ip address in a text file named as write.txt. Add that blank text file in directory and change CHMOD to 777 (in case of online server). CHMOD is file permissions. And when these are set to 777, server assumes that file is readable, writable and executable for all.

Form Usage (Code)

<p>Writing variables to a text file</p>
<form action="write.php" method="post">
<p>Name: <input name="n" type="text" id="n">
Email address: <input name="e" type="text" id="e">
<input type="submit" name="Submit" value="Submit">

PHP Usage (Code)

$domain = GetHostByName($REMOTE_ADDR);
$file = "write.txt";
$fp = fopen ("$file","a");
fputs($fp, "$n | $e | $domain");
echo "Info written to file";
<a href="write.txt" target="_blank">Open File</a>

More Reference


Writing in a File Using PHP – Download Script

Related Posts

Previous post:

Next post: