Connecting Tech Pros Worldwide Forums | Help | Site Map

fclose(): 15 is not a valid stream resource

Member
 
Join Date: Jun 2009
Posts: 52
#1: Jun 26 '09
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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Warning:  fclose(): 15 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
  3.  
  4. Warning:  fclose(): 20 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
  5.  
  6. Warning:  fclose(): 25 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
  7.  
  8. Warning:  fclose(): 25 is not a valid stream resource in /mnt/raid/www/intra/admin/ts2/test2.php on line 174
  9.  
What do the numbers (15,20,25) mean? Thanks in advance.

Member
 
Join Date: Jun 2009
Posts: 52
#2: Jun 26 '09

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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#3: Jun 26 '09

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
#4: Jun 26 '09

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!
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     if ($handle = opendir('/projects/ts/')) {
  4.  
  5.    while (false !== ($folder = readdir($handle)))
  6.       {
  7.           if ($folder != "." && $folder != "..")
  8.         {    
  9.             if(is_numeric($folder)){
  10.                 //writing all data into array
  11.         if($folder<=$end && $folder>=$beginning){        
  12.         $handle2="/projects/ts/".$folder;
  13.         print_r($handle2);
  14.         $folderpath=opendir($handle2);
  15.         print_r($folderpath);
  16.         while(false !== ($file = readdir($folderpath))){
  17.             $tmp=explode('.',$file);
  18.             if($tmp[0]==$folder){
  19.                 print_r($file);
  20.                 $filepath="/projects/ts/".$folder."/".$file;
  21.                 $timesheet=fopen("$filepath", "r");
  22.                 while(!feof($timesheet)){
  23.                 $lines=fgets($timesheet);
  24.                 if($lines{0}=='M'){
  25.                 $user=explode('=',$lines);
  26.                 $user=$user[1];
  27.                 }
  28.                 elseif($lines{0}==null || $lines{0}=='['){
  29.                 }
  30.                 else{
  31.                     //$parts2=explode(' % ',$invalidcheck);
  32.                     $parts3=explode('=', $lines);
  33.                     $parts4=explode('.', $parts3[0]);
  34.                     $project=$parts4[0];
  35.                     $project=trim($parts4[0]);
  36.                     $phase=$parts4[1];
  37.                     $hours=$parts3[1];
  38.                     $hours=substr($parts3[1],0,4);            
  39.                 }    
  40.                 if($project==$type){    
  41.                 $classpath="/projects/".$project."/ts_classes";
  42.                 $classfile=fopen("$classpath","r");
  43.                 while(!feof($classfile)){
  44.                 $classes=fgets($classfile);
  45.                 $classes=preg_replace('/\s\s+/',' ', $classes);
  46.                 $tmp=explode(' ',$classes);
  47.                 if($tmp[1]==$user){
  48.                     if($tmp[3]{1}=='-'){
  49.                         $time=substr($tmp[3],2,6);
  50.                         if($time<=$lastdate && $time>=$firstdate){
  51.                         $class=$tmp[2];
  52.                         $checker=1;
  53.                         }
  54.                         }
  55.                     elseif($tmp[3]{8}=='-'){
  56.                         $time=substr($tmp[3],1,6);
  57.                         if($time<=$lastdate && $time>=$firsdate){
  58.                             if($checker==0){
  59.                             $class=$tmp[2];
  60.                             }
  61.                             else{
  62.                             $class2=$tmp[2];
  63.                             }
  64.                         }
  65.                         }
  66.                     else{
  67.                     $class=$tmp[2];
  68.                     print_r($class);
  69.                     }
  70.                 }
  71.                 else{
  72.                 }
  73.                 }
  74.                 fclose($classpath);
  75.  
  76.                     }        
  77.             }            
  78.         }
  79.         fclose($timesheet);
  80.         }
  81.         closedir($folderpath);
  82.             }
  83.           }
  84.        }
  85.         }
  86.  closedir($handle);
  87.  
  88.  
  89.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#5: Jun 26 '09

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
#6: Jun 26 '09

re: fclose(): 15 is not a valid stream resource


The error is showing up for fclose($timesheet) in line 79. Thanks=)
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#7: Jun 26 '09

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
#8: Jun 30 '09

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.
Reply