File handling 

Posted on

What is file handling in php ?

File handling is the concept of handle the files like text file,doc file etc. Handling means communication files with php and operate on them like edit delete add new text etc.

This is the very useful concept in php with one line of code we can read the file and we can write on the file.

lets learn how to make a file and operate on it.

First Step:

Create a text file fill with text and name is hellocheck.txt and save it in same folder where you put your php page.

Second Step:

Open notepad++ and make a php page where you have to write the code to read the text file which we create In first step.

Syntax to read the file


echo readfile(“filename.txt”);


This code tell the file content and as well as count of the words.

Third step:

How to write into the file ?

1st make a form:-

<h1>Input the value in file</h1>

<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>

<input type=”text” name=”message” placeholder=”Enter the Message”>

<input type=”submit” name=”sub” value=”sub”>


2nd create php code:-





$mf=fopen(“a.txt”,”w+”)or die(“data not entered successfully please try again.”);


echo “data inserted”;




This program write the text into file when we submit the form it pick the value from the text box and store it into variable name $text and now next step is to open the file there are two parameter first is file name and second is mode of the file we want to write or read w+ is use to read and write both. Then We call fwrite function we pass two parameter first is file open variable and second is $text variable which use to write the text into the file and message shown data inserted and file is close with fclose() function use to close the file.

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666


Please fill the FORM and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s