Page 1 of 1

Error: not valid stream resource (in a class)

Posted: Sun Dec 08, 2013 3:32 pm
by murfy
HI, I need a little help
http://pastebin.com/ardzHaUh
See lines 392 - 398

Code: Select all

<?php 
include("scan_ips_class.php");
$scanIPs = new Scan_ips;
?>
When I run this script I got error:
Warning: fseek(): 5 is not a valid stream resource in P:\server\scan_ips\scan_ips_class.php on line 402

Whilst I understand that the file hanlder is not valid, I cannot find out why it is not valid.
There is this line:
if ( !$this->FRWBHandler )
$this->FRWBHandler = @fopen($this->file,"r+b");
which should set the file hanlder. In fact, I see that the file handle is set, because I print it by echo. If I will add this line:

Code: Select all

$this->FRWBHandler = @fopen($this->file,"r+b");
So it will not generate any error, but it will generate new resource id which is not what I wanted to do.

Just to explain what I do in the class:
I add IPs into file, but before I add it I want to check if it already exist or not, so I run function to check it. So if I call the check, the file will be opened so I won't need to close it and then reopen it again. This is why I added the shared file handler called $this->FRWBHandler

So my question is what is wrong that is does not work as I expect. Either it will not accept the resource (resource 5) or it will generate new resources If I will ignore that the resource is already opened.

Re: Error: not valid stream resource (in a class)

Posted: Sun Dec 08, 2013 11:54 pm
by Eric!
Odds are good it can't read the file for whatever reason and if you remove the @ you'll see the error_warning in your log.

Code: Select all

$this->FRWBHandler = fopen($this->file,"r+b");
Also what is (!$this->FRWBHandler) ? If for some reason it is not false you might not be calling fopen.

Re: Error: not valid stream resource (in a class)

Posted: Mon Dec 09, 2013 2:57 am
by murfy
Solved. I had to move fclose.