PHP Tutorial - 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
      $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".