- PHP fclose function is used to close a file.
- One should close all files after finish their work with them because it’s a good programming practice and you should be follow it!
PHP fclose Function
- In previous topics we have seen the fclose functions in many examples. flcose function is basically used to close down the file in PHP. Here we are going to show you a simple example of flcose function:
$myfile = "open.txt";
$myfilehandle = fopen($myfile, 'w') or die("can't open file");
- In the above example fclose function will close the opened file “open.txt”.The function fclose requires the file handle that we want to close down. In our example we set our variable “$myfilehandle” equal to the file handle returned by the fopen function.
- We should close the file after finish our work with them because it is a sign of good programmers. After a file has been close with flcose function no one can read, write or append it. One should re-open the file with the fopen function to work with it again.