Posted By:
16 Mar, 2014 3:23 am PDT

Opening file in PHP

How to open and close a file in PHP?

 

In order to open a file we can use the function-fopen() which take name of the file as well as mode ,as its two parameter.

There are various modes.The table of some modeshas been given below:

r

For read only

r+

For read/write

W

For write only which creates the new file if does not exit or open and clear the content of the file.

w+

It is for both read and write which creates the new file if does not exit or open and clear the content of the file.

a

It opens and write to the end of the file

 

//Code to open and close file using PHP 

<!DOCTYPE html>

<html>

<body>

<?php

$file = fopen("text.txt","r");

fclose();

?>

</body>

</html> 

 

Attachment: open.php


It illustrate How to open text file (.txt extension) using PHP

Was it useful?  




Please login to reply to this problem.