MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

Tutorial for Closing File in PHP

php

Closing file in php is all related to fclose( ) Function. With the help of this code we can run closing function in php.

What is fclose( ) Function in php?

In PHP, the fclose() method is used to close a file referenced by an open file pointer. If the method fclose() is successful, it returns true; otherwise, it returns false. It accepts the file that needs to be closed as an input and closes it.

Syntax:

bool fclose( $file )

Parameters:

The $file argument is the only one accepted by PHP’s fclose() function. The file that has to be closed is specified by this argument.

Return Value:

If it succeeds, it returns true; if it fails, it returns false.

Errors And Exception:

  • If you want to read the contents of a file that was written using the fwrite() function, you must first shut it with the fclose() function.
  • For remote files, PHP’s fclose() method does not work. It only works with files that the server’s filesystem can access.

Let’s take examples to explain this function:

Input : $check = fopen("gfg.txt", "r");
        fclose($check);
Output : true

Input: $check = fopen("singleline.txt", "r");
       $seq = fgets($check);
       while(! feof($check))
       {
         echo $seq ;
         $seq = fgets($check);
       }
       fclose($check);
Output:true

Example 1:-

Output:

Example 2:- The file test.txt in the software below includes just one line: “This file contains only one line.”

Output:

Ashwani Kumar
Latest posts by Ashwani Kumar (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x