An important part of PHP is to handle and manipulate a file. It happens quite often when a file needs to be opened by an user, or the code, and it's content has to be manipulated; for instance read and edited. PHP provides many functions to manipulate files but it is very important to understand possible negative implications if mishandled.

The most common function is readfile(). The readfile() function can be used very easily in PHP; in the same way, it also provides the functionality to write, edit and manipulate a file.

Basic example with readfile() function

<?php
    echo readfile("../dir_path/file_name.txt");
?>

 

Continue reading about files manipulation techniques.

 

›› go to examples ››