PhpMyanmar.com logo Php Tutorial
Home
Php Tutorial
 Echo
 If

File Close
Show Myanmar Version
 show-myanmar-font
Printer Friendly Page

After you have opened a file and finished your business you need to close that file.

Don't keep an unnecessary open file on your server as it taking up resources and can cause mischief!

File Close Description

In PHP it is not system critical to close all your files after using them because the server will close all files after the PHP code finishes execution.

However the programmer?could make mistakes (i.e. editing a file that you accidentally forgot to close).

You should close all files after you have finished with them because it's a good programming practice.

File Close Function

We will examine the?example below and discuss the importance of closing a file.

PHP Code:
$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

The function fclose requires the file handle that we want to close down.?

In our example above we set our variable "$fileHandle" equal to the file handle returned by the fopen function.

After a file has been closed down with fclose it is impossible to read, write or append to that file unless it is once more opened up with the fopen function.

Note
For more detail please see Php Manual at http://www.php.net

Processing time -- 0.0768 seconds.

cd412e764f2a15813c68ada714cbf580