fclose(): 15 is not a valid stream resource | Member | | Join Date: Jun 2009
Posts: 52
| |
I'm not sure what this error means and was wondering if anyone knew what the problem is and how it can be fixed. This error comes out multiple times but each time the number is different. -
-
Warning: fclose(): 15 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
-
-
Warning: fclose(): 20 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
-
-
Warning: fclose(): 25 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
-
-
Warning: fclose(): 25 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
-
What do the numbers (15,20,25) mean? Thanks in advance.
| | Member | | Join Date: Jun 2009
Posts: 52
| | | re: fclose(): 15 is not a valid stream resource
So after tinkering around for a while, I learned that these numbers correspond to the resource id# which I'm also not sure what it is. When I printed out the file name, it says resource id # then the actual file name. And since in the loop it opens 15 different files, the resource id becomes 15. How do I get it to close the file and no the resource id.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: fclose(): 15 is not a valid stream resource
Maybe if we could see the code causing the error, our responses would be slightly more informed.
| | Member | | Join Date: Jun 2009
Posts: 52
| | | re: fclose(): 15 is not a valid stream resource
sorry=P..it's just that actual code is really long and I'm not even sure which section to post. I tried cutting out the unnecessary lines, but here it is. Thanks for your help! -
-
-
if ($handle = opendir('/projects/ts/')) {
-
-
while (false !== ($folder = readdir($handle)))
-
{
-
if ($folder != "." && $folder != "..")
-
{
-
if(is_numeric($folder)){
-
//writing all data into array
-
if($folder<=$end && $folder>=$beginning){
-
$handle2="/projects/ts/".$folder;
-
print_r($handle2);
-
$folderpath=opendir($handle2);
-
print_r($folderpath);
-
while(false !== ($file = readdir($folderpath))){
-
$tmp=explode('.',$file);
-
if($tmp[0]==$folder){
-
print_r($file);
-
$filepath="/projects/ts/".$folder."/".$file;
-
$timesheet=fopen("$filepath", "r");
-
while(!feof($timesheet)){
-
$lines=fgets($timesheet);
-
if($lines{0}=='M'){
-
$user=explode('=',$lines);
-
$user=$user[1];
-
}
-
elseif($lines{0}==null || $lines{0}=='['){
-
}
-
else{
-
//$parts2=explode(' % ',$invalidcheck);
-
$parts3=explode('=', $lines);
-
$parts4=explode('.', $parts3[0]);
-
$project=$parts4[0];
-
$project=trim($parts4[0]);
-
$phase=$parts4[1];
-
$hours=$parts3[1];
-
$hours=substr($parts3[1],0,4);
-
}
-
if($project==$type){
-
$classpath="/projects/".$project."/ts_classes";
-
$classfile=fopen("$classpath","r");
-
while(!feof($classfile)){
-
$classes=fgets($classfile);
-
$classes=preg_replace('/\s\s+/',' ', $classes);
-
$tmp=explode(' ',$classes);
-
if($tmp[1]==$user){
-
if($tmp[3]{1}=='-'){
-
$time=substr($tmp[3],2,6);
-
if($time<=$lastdate && $time>=$firstdate){
-
$class=$tmp[2];
-
$checker=1;
-
}
-
}
-
elseif($tmp[3]{8}=='-'){
-
$time=substr($tmp[3],1,6);
-
if($time<=$lastdate && $time>=$firsdate){
-
if($checker==0){
-
$class=$tmp[2];
-
}
-
else{
-
$class2=$tmp[2];
-
}
-
}
-
}
-
else{
-
$class=$tmp[2];
-
print_r($class);
-
}
-
}
-
else{
-
}
-
}
-
fclose($classpath);
-
-
}
-
}
-
}
-
fclose($timesheet);
-
}
-
closedir($folderpath);
-
}
-
}
-
}
-
}
-
closedir($handle);
-
-
-
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: fclose(): 15 is not a valid stream resource
Line 74 of the code you posted above should be fclose($classfile); not $classpath. I cannot spot the other errors. Can you show which lines (in the code you posted) are the lines that your errors point to?
Thanks.
| | Member | | Join Date: Jun 2009
Posts: 52
| | | re: fclose(): 15 is not a valid stream resource
The error is showing up for fclose($timesheet) in line 79. Thanks=)
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: fclose(): 15 is not a valid stream resource
Argh. Format your code!
Anyway, it looks like you are doing $timesheet=fopen("$filepath", "r"); inside an if conditional, and then when this if conditional ends, you attempt to fclose() the resource. But, what happens if the if is skipped? The resource is not created and fclose() is trying to close something that doesn't exist.
| | Member | | Join Date: Jun 2009
Posts: 52
| | | re: fclose(): 15 is not a valid stream resource
sorry i forgot to reply but you're correct, that was the problem.Thanks=) I found that I did this for a lot of the fclose so its a good thing you caught it for me.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,533 network members.
|