-Zeus- Posted March 21, 2009 Share Posted March 21, 2009 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 More sharing options...
WolfRage Posted March 21, 2009 Share Posted March 21, 2009 You are trying to make PHP evaluate a stream reference, which is a impossibility. <?php fclose($open); ?> Link to comment https://forums.phpfreaks.com/topic/150485-fclose-error/#findComment-790385 Share on other sites More sharing options...
-Zeus- Posted March 21, 2009 Author Share Posted March 21, 2009 I got this from the php reference on fclose() at http://us.php.net/manual/en/function.fclose.php $handle = fopen('somefile.txt', 'r'); fclose($handle); Isn't that what I am doing? Link to comment https://forums.phpfreaks.com/topic/150485-fclose-error/#findComment-790395 Share on other sites More sharing options...
WolfRage Posted March 21, 2009 Share Posted March 21, 2009 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 More sharing options...
PHP Monkeh Posted March 21, 2009 Share Posted March 21, 2009 fclose("$open"); Remove the quotes around $open so it looks like this: fclose($open); Link to comment https://forums.phpfreaks.com/topic/150485-fclose-error/#findComment-790401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.