Thursday, May 23, 2013

Write A Text File

For Writing a Text file we make three files in one folder.
  1. index.php [ which contain some HTML input container and a submit button]
  2. filewrite.php [ it is a server script page]
  3. file.txt [create a blank text file]


index.php 

------------------------------

<form action="filewrite.php" method="POST">
     Name:<input type="text" name="name"><br>
     Pass:<input type="text" name="pass"><br>
     Type:<input type="text" name="type"><br>
     <input type="submit" value="Submit"><br>
</form>

----------------------------------

filewrite.php

----------------------------------

<?php

$file = fopen("file.txt","a");// "a" means append 

fwrite($file,"name:".$_POST["name"]."\r\n"."type:".$_POST["type"]."\r\n"."pass:".$_POST["pass"]."\r\n");

fclose($file);

?>
---------------------------------

Run the index.php file then see what happen ..
it's too simple to write a text file.
Go and open your  " file.txt " .....

Keep Smile  :)

No comments:

Post a Comment