Search This Blog

file write in php

<?php

if(isset($_POST['name'])&&isset($_POST['age'])&&isset($_POST['fname']))
{
  $name=$_POST['name'];
  $age=$_POST['age'];
  $fname=$_POST['fname'];
  if(!empty($name)&&!empty($age)&&!empty($fname))
  {
    $hand=fopen($fname.'.txt','w');
    fwrite($hand,$name." ");
    fwrite($hand,$age."\r\n");
    fclose($hand);
  }
 else
    echo 'fill all fields';
}
?>

<form action="file-write.php" method="POST">
name :<input type="text" name="name">
age :<input type="text" name="age">
file name : <input type="text" name="fname">
.txt
<input type="submit" value="submit">
</form>

output :


note :
1) enter all fields
2) the last field is file name
3) first it clears all data from that file and write you entered data into that file
4)if that file not exists then it creates and write that file

Share Links

Related Posts Plugin for WordPress, Blogger...