Easy learning with example program codes

PHP File Handling

File handling simply means to open a file and to process it according to the required tasks. PHP facilitates several functions to create, read, write, append, delete and close files.

Open File:
To open a file in PHP, fopen() function is used.


resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

Close File:
To close a file in PHP, fclose() function is used.
ool fclose ( resource $handle )  
Read File:
To read a file in PHP, fread() function is used.
string fread (resource $filename , int $filesize )  
Write File:
To write a file in PHP, fwrite() function is used.
int fwrite ( resource $handle , string $string )  
Delete File:
To delete a file in PHP, unlink() function is used.
bool unlink ( string $filename [, resource $context ] )  


<!DOCTYPE html>
$samplefile = fopen("phpfile.txt", "r");
echo fread($samplefile,filesize("phpfile.txt"));


Test file
Posted in PHP   

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki