Products
Services
Contact Us

Scripts: PHP :: PHP file system >> Library Article #7

Developer's Section

Write data to a text file
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1866)
Favorites:

Follow this simple steps to be able to write data to a text file.

Here are two basic steps to write data to a text file in your server:

Note:File permissions must be set to 777 on the file.

Create A simple Form:

 Code Snippet 1

<form name="subscribe_form" method="post" action="signup.php" >
Email: 
<input type="text" name="email" value="" size="20"><br>
First Name: 
<input type="text" name="firstname" value="" size="20"><br>
Last Name: 
Last Name: 
<input type="text" name="lastname" value="" size="20"><br>
<input type="submit" name="mysubmit" value="Submit">
</form>


Write php Code on your file:

 Code Snippet 2

<? // process

if(trim($_POST["mysubmit"]) == "Submit") {

$email = trim($_POST['email']);
$first_name = trim($_POST['first_name']);
$last_name = trim($_POST['last_name']);


$fileString = $email . "\t";
$fileString .= $first_name . "\t"; 
$fileString .= $last_name . "\t\n";

$file_name = realpath("./") . "subscription.txt";
//open file pointer
$fp = fopen ($file_name, "a"); 
//write data 
fwrite ($fp,$fileString);
//close handler      
fclose ($fp);       

Header("Location: thanks.html");

}


See other Scripts in PHP file system

Submit Your Scripts:

If you would like to have your PHP scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]