PHP File Handling plays a great role in any web application. Regularly in each and every web application a file can be opened using fopen() and will close the opened files using fclose().
PHP File Manipulation
Description
Different operations in file handling are performed by creating, reading, editing and uploading the files.
Proper checking is required when working on file manipulations. It is important to check the creation of file and at the time of editing the file. Sometimes improperly editing files leads to loss of the secured data.
PHP readfile() Function
Description
Using PHP readfile() function, only read permission can be given to the users.They cannot edit or update the file.
Example
example.txt
[php]
<!DOCTYPE html>
<html>
<body>
<?php
echo readfile("random.txt");
?>
</body>
</html>
[/php]
random.txt
[php]Hello!! This is SPLessons PHP tutorial.
You are reading PHP readfile() function example.[/php]
Output:
Summary
Key Points
File is collection of data.
Opening, closing, writing, reading,deleting and renaming are the functions performed on file.