php fclose() 函数关闭一个已打开的文件指针

时间:2016-08-08
php fclose() 函数用于关闭由fopen打开的文件,本文章向大家介绍php fclose() 函数的基本使用方法和实例,需要的朋友可以参考一下。

fclose()介绍

fclose — 关闭一个已打开的文件指针 

语法:

bool fclose  ( resource $handle  )

将 handle 指向的文件关闭。 

参数

  1. handle 文件指针必须有效,并且是通过 fopen()  或 fsockopen()  成功打开的。 

返回值:成功时返回 TRUE , 或者在失败时返回 FALSE 。 

fclose()实例

使用fclose()函数关闭一个已经打开的文件指针:

<?
    $file = "data.txt";
    /* http://www.manongjc.com/article/1326.html */
    if (file_exists($file)) :
         $fh = fopen($file, "r");
         fclose($fh);
    else:
         print "File $file does not exist!";
    endif;
?>