Suhail Gupta
Suhail Gupta

Reputation: 23276

what does fopen return?

In the following statement :

$handle = fopen('./readme.txt');

what variable is $handle ? Is it a boolean or what ?

I am in a doubt after running these 2 different statements :

if($handle) echo "File opened !"
else echo "Error opening the file !";

and

$line = fgets($handle);

So what variable is actually $handle ?

Upvotes: 3

Views: 4122

Answers (2)

juco
juco

Reputation: 6342

It returns either a resource or boolean false. Resources are known as a special type and are explained in detail here

Upvotes: 6

Leo Chapiro
Leo Chapiro

Reputation: 13994

Returns a file pointer resource on success, or FALSE on error.

http://php.net/manual/en/function.fopen.php

Upvotes: 3

Related Questions