Jump to content

fclose() error


-Zeus-

Recommended Posts

I have a php script that reads in files and echoes the output, but I am getting a strange error:

 

$handle = opendir(rank);
while (($file = readdir($handle)) == true) {
  $file = 'rank/' . $file;
  $open = fopen("$file",r);
  $data = fread($open,filesize("$file"));
  fclose("$open");
  echo $data;
}
closedir($handle);

It runs fine, and I get the output, but the server logs say:

fclose(): supplied argument is not a valid stream resource in /**********/includes/common.inc(1344) : eval()'d code on line 6.

Link to comment
https://forums.phpfreaks.com/topic/150485-fclose-error/
Share on other sites

Putting a variable in double qoutes, puts php in evaluation mode. But you can not evaluate a stream reference, because it is a memory reference to a file. Either pass the file this way:

<?php
fclose('my_file/text.php');
?>

or this way:

<?php
fclose($file_pointer);
?>

but do not combine them.

Link to comment
https://forums.phpfreaks.com/topic/150485-fclose-error/#findComment-790400
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.