PHP Programing language

adplus-dvertising
PHP Close a File
Previous Home Next

After opening a fil eand creating ityou will then close the file, it's a logical step after opened a file and finished your business i.e,closing the file.You don't want an open file running around on your server taking up resources and causing mischief.

What is File Close Description

In the PHP it's not system critical to close all your files after used. Because the PHP program executed successfully then after the server will close all files. However the programmer is still free to 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 and because we told you to do.

What is File Close Function

In a previous tutorial, we had a call to the function fclose to close down a file after we were done with it. Here we will repeat that example and discuss the importance of closing a file.

PHP Code:

<?php
$FileName = "firsttext.txt";
$FileHandle = fopen ($FileName, 'w') 
or die ("can't be write this file");
fclose ($ourFileHandle);
?>

The function fclose() must handle the that we want to close down. In our example 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 that file, unless it is once more opened up with the fopen function.

Previous Home Next