codescracker


php

PHP Close File



« Previous Tutorial Next Tutorial »


To close a file in PHP, use fclose() function.

PHP Closing a File Example

Here is an example of closing a file in PHP after opening the file and performing some action.

<html>
<head>
	<title>Closing a file in PHP</title>
</head>
<body>
<?php
	echo "<p>Opening the file <b>codescracker.txt</b> .....</p>";
	$myfile = fopen("codescracker.txt", "r");
	if($myfile == false)
	{
		echo "Error occurred...exiting...";
		exit();
	}
	echo "<p>File opened successfully.</p>";
	echo "<p>Closing the file....</p>";
	fclose($myfile);
	echo "<p>File closed successfully.</p>"
?>
</body>
</html>

Here is the sample output produced by the above closing a file example code in PHP

php closing file

« Previous Tutorial Next Tutorial »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test