Home > Backend Development > PHP Problem > How to close a file in php

How to close a file in php

青灯夜游
Release: 2023-03-13 08:02:01
Original
2134 people have browsed it

In PHP, you can use the fclose() function to close a file. This function can close an open file pointer with the syntax "fclose($handle)"; if the closing is successful, TRUE will be returned. Returns FALSE on failure.

How to close a file in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The resource type is one of the basic types of PHP. Once you have finished processing the resource, be sure to close it, otherwise some unexpected errors may occur.

The function fclose() can close an open file pointer, returning TRUE if successful and FALSE if failed. The syntax format of the function is as follows:

fclose(resource $handle)
Copy after login

where $handle is the file pointer to be closed. This pointer must be valid and successfully opened through the fopen() or fsockopen() function.

[Example] Use fclose() to close the file pointer.

<?php
    $handle = fopen("test.txt", "r");
    echo &#39;文件指针关闭之前:&#39;;
    var_dump($handle);
    fclose($handle);
    echo &#39;<br>文件指针关闭之后:&#39;;
    var_dump($handle);
?>
Copy after login

The running results are as follows:

文件指针关闭之前:resource(3) of type (stream)
文件指针关闭之后:resource(3) of type (Unknown)
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to close a file in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template