CodesJava

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.

Syntax:

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.
Syntax:
ool fclose ( resource $handle )  
Read File:
To read a file in PHP, fread() function is used.
Syntax:
string fread (resource $filename , int $filesize )  
Write File:
To write a file in PHP, fwrite() function is used.
Syntax:
int fwrite ( resource $handle , string $string )  
Delete File:
To delete a file in PHP, unlink() function is used.
Syntax:
bool unlink ( string $filename [, resource $context ] )  

Example:

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

Output

Test file
Posted in PHP   
Sign Up/ Sign In
Ask a Question


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 hr@codesjava.com.

Development

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

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki