PHP fclose() Function
In this chapter you will learn:
- Definition for PHP fclose() Function
- Syntax for PHP fclose() Function
- Parameter for PHP fclose() Function
- Return for PHP fclose() Function
- Example - close a file
Definition
The fclose() function closes an open file.
Syntax
PHP fclose() Function has the following syntax.
fclose(file)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | 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 j av a 2s . co m*/
$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".
Next chapter...
What you will learn in the next chapter:
- Definition for PHP feof() Function
- Syntax for PHP feof() Function
- Parameter for PHP feof() Function
- Return for PHP feof() Function
- Example - checks if the "end-of-file" (EOF) has been reached
Home » PHP Tutorial » PHP File Functions