PHP fclose() Function

Definition

The fclose() function closes an open file.

Syntax

PHP fclose() Function has the following syntax.

fclose(file)

Parameter

ParameterIs RequiredDescription
fileRequired.Specifies the file to close

Return

PHP fclose() Function returns TRUE on success or FALSE on failure.

Example

To close a file you have opened with fopen(), use fclose().


<?PHP/*from www  . ja  v a 2  s.  c om*/
      $filename = "c:/abc/test.txt";
      $handle = fopen($filename, "rb");
      $contents = fread($handle, filesize($filename));
      fclose($handle);
      print $contents;
?>

In that example, fopen() is called with rb as the second parameter, for "read-only, binary-safe".





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions