search
HomeBackend DevelopmentPHP ProblemHow to close files opened by fopen in php

How to close files opened by fopen in php

Jul 15, 2021 pm 12:07 PM
fclosefopenphpclose file

The file opened by fopen in php can be closed using the fclose() function. The fclose() function can close an open file pointer and an open file. The syntax format is "fclose(handle)"; Returns true if successful, false otherwise.

How to close files opened by fopen in php

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

Use the fopen() function in PHP to open the file Or URL. If the opening is successful, the file pointer resource is returned; if the opening fails, FALSE is returned.

The open file can be closed using the fclose() function.

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)

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.

<?php
    $handle = fopen("http://c.biancheng.net/", "r");
    echo &#39;文件指针关闭之前:&#39;;
    var_dump($handle);
    fclose($handle);
    echo &#39;<br>文件指针关闭之后:&#39;;
    var_dump($handle);
?>

The running results are as follows:

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

Note: The resource type is one of the basic types of PHP. Once the resource processing is completed, it must be closed, otherwise some problems may occur. Unexpected error.

Recommended learning: "PHP Video Tutorial"

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment