PHP fclose() Function

PHP fclose Function


Definition :

The fclose() function in PHP is an inbuilt function which is used to close a file which is pointed by an open file pointer

Syntax:

  fclose( $file )

Parameters: The fclose() function in PHP accepts only one parameter which is $file. This parameter specifies the file which has to be close.

Errors And Exception:

  1. A file has to be closed first using the fclose() function if it has been written via fwrite() function and you have to read the contents of the file.
  2. The fclose() function in PHP doesn’t works for remote files.It only works on files which are accessible by the server’s filesystem.

Given below example Open and close file "demo.txt":