473,554 Members | 3,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fclose(): 15 is not a valid stream resource

52 New Member
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.
Jun 26 '09 #1
7 16644
phpnewbie26
52 New Member
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.
Jun 26 '09 #2
Markus
6,050 Recognized Expert Expert
Maybe if we could see the code causing the error, our responses would be slightly more informed.
Jun 26 '09 #3
phpnewbie26
52 New Member
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.  
Jun 26 '09 #4
Markus
6,050 Recognized Expert Expert
Line 74 of the code you posted above should be fclose($classfi le); 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.
Jun 26 '09 #5
phpnewbie26
52 New Member
The error is showing up for fclose($timeshe et) in line 79. Thanks=)
Jun 26 '09 #6
Markus
6,050 Recognized Expert Expert
Argh. Format your code!

Anyway, it looks like you are doing $timesheet=fope n("$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.
Jun 26 '09 #7
phpnewbie26
52 New Member
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.
Jun 30 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
5130
by: Jeff | last post by:
If this in not an ANSI-C question, then just flame me and I'll be on my way.... I am using fdopen to associate a FILE with a socket descriptor. (Because I've mentioned a socket descriptor I anticipate the flame. But I believe this is a C question.) My problem is this: if the socket is closed and I pass the FILE returned from fdopen to...
19
6771
by: lihua | last post by:
Hi, Group! I got one question here: We all know that fclose() must be called after file operations to avoid unexpected errors.But there are really cases when you forget to do that!Just like what happens in memory operations, everyone knows the importance of freeing the allocated memory, but there do have memory leaks from time to
0
500
by: Daniel Groh | last post by:
Yesterday I asked about this error (Stream is not a valid resource file.) and the friend here asked if the resx file was in a correct format. I think so, because I just added 2 values in the name field and in the value field. SHould I make somethink else special ? Essential ? ------------- This line: Line 40: ResourceReader objResReader =...
1
2243
by: coz | last post by:
Someone please help! I cannot for the life of me get a web resource in asp.net 2.0 to return any content. I know I have correctly embedded my resources (because I can manually get the resources from my assemblies at runtime.) The URLs I get back are valid (they throw no errors) but they return zero content. I get a broken page from...
17
14762
by: kathy | last post by:
if fopen failed, does it necessary to call fclose? I see an example like this: .... stream = fopen(...); if(stream == NULL) { .... } else
20
7264
by: David Mathog | last post by:
A program of mine writes to a tape unit. Output can be either through stdout or through a file opened with fopen(). When all the data is transferred to tape the program needs to close the output stream so that the tape driver will write a filemark on the tape. Otherwise multiple clumps of data saved to tape would all appear to be one big...
2
10277
by: yogitha | last post by:
For the below code i am getting an error like : --------------------------------------------------------------- Warning: fread(): supplied argument is not a valid stream resource in D:\Public_Site\multifileupload\welcome_addfiles.php on line 28 ------------------------------------------------------------ i am trying many ways by giving diff...
53
4410
by: Bartc | last post by:
This short program: #include <stdio.h> #include <stdlib.h> int main(void) { int status; status=fclose(0);
16
2575
by: Bill Cunningham | last post by:
Is it really necessary to check the return type (int) or fclose ? fopen I can understand but what about using fflsuh(fp); /* fopen's pointer */ fclose(fp); Would that take care of any unforseen truncation ? Bill
0
7519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7798
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5152
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
838
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.