How to use file functions in php

How to use file functions in php

In this tutorials I will show you How to use file functions in php, how to read the file and write the file using php functions.

First make test.txt file and put some dummy content in that file.

Note: Make test.txt file group permission to 777 or writeable and readable.

<?php
$fp = fopen("test.txt","w");
 while(!feof($fp))
 {
 $data = fgets($fp);
 echo "alert($data);";
 }
 fwrite($fp, 'this is test text');
 fclose($fp);
?>

Using following function You are able to check the file size.

$fp = fopen('test.txt', 'r');
echo $data = fread($fp, filesize('test.txt'));
fclose($fp);
How to use file functions in php
How to use file functions in php

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “How to use file functions in php”

Leave a Reply to Anibal Mehr Cancel reply

Your email address will not be published.