Page 1 of 1

How to check whether readfile was successful?

Posted: 20 Sep 2016 11:34
by autocart
$text = readfile($inputfile);

?? Thx.

Re: How to check whether readfile was successful?

Posted: 20 Sep 2016 12:08
by PeterH
Not really exact - but test $text for "" :?:

Re: How to check whether readfile was successful?

Posted: 20 Sep 2016 12:19
by autocart
if it was that simple I would not ask :wink:
i could think of contexts where $text might be "" before and if the file was empty then it might have the same result.
maybe i could check at the same time if property("size") == 0 but I am not sure if this is the case for all files who's readfile() results in "".

Of course, some errors (e.g. if the file is missing) result in a scripting error.
I don't know if all errors do that. (Because in this case this case would be closed.) Or if some silently return "" anyway.
If Don could enlighten us about that it would be nice, please, thx.

Re: How to check whether readfile was successful?

Posted: 20 Sep 2016 15:33
by admin
It pops an error on failure.

Re: How to check whether readfile was successful?

Posted: 20 Sep 2016 16:16
by autocart
admin wrote:It pops an error on failure.
ok, thx.