This article introduces how to close an open file in PHP programming. Friends in need can refer to it.
In PHP, when a file is opened for related operations, the file handle needs to be closed in time to avoid long-term resource occupation. php close file In PHP programming, when you finish using a file, you must close it in time. This is a good habit. php function or method to close a file To close a file in php, you need to use the function fclose. The following is an example of closing a file for reference. Code: <?php //关闭文件 $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); //by bbs.it-home.org ?> Copy after login Code description: The fclose function requires a file handle to be closed. In the above example, we set the variable "$ourFileHandle" to the file handle returned by the fopen function. After performing the above operation, the opened file testfile.txt will be closed. Any subsequent operations such as reading or appending the file content will be invalid. The above operation can only continue when the access file is opened again. This is about how to close files in php. I hope it will be helpful to everyone. |