Menu

#2 Check the file pointers before reading

v1.0_(example)
closed-fixed
None
5
2001-12-07
2001-12-06
Anonymous
No

I just downloaded your source because i wonderd how it
works.
I have seen that you read data from file without
checking if the file is ready to stream data (or even
if the file is opened)

What you use @ the moment is :

$filepointer = fopen("filename.file","r");
while (!feof($filepointer)){
$foobar .= fgets($filepointer, 1024);
}
fclose($filepointer);

A much nicer way is to do it this way :

if ($filepointer = fopen("filename.file","r")){
/* Ok nice file opened get data */
while (!feof($filepointer)){
$foobar .= fgets($filepointer, 1024);
}
fclose($filepointer);
} else {
/* There is a problem with opening the file... */
die("We where unable to open the file
'filename.file'\nMaybe the file doesn't exists or you
don't have\nthe right permisions to access the file.\n");
}

I hope you can use it,

With kind regards,

Sander Aerts CEO SQAD Visual Multi-Media

Discussion

  • Rich Payne

    Rich Payne - 2001-12-07

    Logged In: YES
    user_id=94895

    Thanks for the info. I've actually re-written most of the
    code to load files for the upcoming 0.20 release so with any
    luck this won't be to much of an issue.

     
  • Rich Payne

    Rich Payne - 2001-12-07
    • assigned_to: nobody --> rdp
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB