File Handling – PHP Advanced

File Handling is the most important part of web application. For different task you need to open and process a file.

Manipulating Files :

Creating, Reading, Uploading, and Editing files has several functions for PHP.
If you do something wrong, it can damage a lot so be careful while manipulating files. Filling a hard-drive with garbage data, editing wrong files and by mistake deleting a content of a file : these are the common errors.

readfile() funtion

This function reads & writes it to output buffer. If you want to open file and read its all contents then readfile() is much useful.

  • At first, i have created a file named “example.txt” which contains the following information :-

This is an example.
#teamcodeprojects – projects, tutorial and more

NOW PHP CODE READs THE FILE AND DISPLAYS THE OUTPUT :

<!DOCTYPE html>
 <html>
 <body>

<?php
 echo readfile("example.txt");
 ?>

</body>
 </html>

Output :

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Naseeb BajracharyaMohit Gupta Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Mohit Gupta
Guest

Could not connect database .

this is the error

Naseeb Bajracharya
Guest

create a database and import SQL file