• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Whats wrong with this? [PHP]

Cagez

New Member
PHP:
class getFile	{

	var $url = "";
	var $bytes = "";
	var $error_code = "";
	var $error_message = "<h1>Error</h1>\nThe following errors have occurred:\n\n<p>\n";
	var $fp;
	var $line_content;
	var $is_open = 0;



	function getFile($url, $bytes)	{
		$url != "" ? $this->url = $url : $this->error_code = 1;
		eregi("e|[0-9]", $bytes) ? $this->bytes = $bytes : $this->error_code .= 2;

		if(eregi("[1-2]", $this->error_code))	{
			if(eregi("1", $this->error_code))
					$this->error_message .= "<li><b>\$web_address</b> has no value. <small><small><i>[Code 1]</i></small></small></li>\n";
			elseif(eregi("2", $this->error_code))
					$this->error_message .= "<li><b>\$bytes_to_read</b> has an incorrect value. <small><small><i>[Code 2]</i></small></small>\n";

			die($this->error_message);
		}
	}



	function openFile()	{
		if($this->is_open = 0)	{
			$this->fp = fopen($this->url, "r") or $this->error_code = 3;

			if($this->error_code = 3)	{
				$this->error_message .= "<li>Could not open <b>$this->url</b> for reading. <small><small><i>[Code 3]</i></small></small></li>\n";
				die($this->error_message);
			}

			$this->is_open = 1;
		}

		else	{
			$this->error_message .= "<li>Could not open <b>$this->url</b>, file is already opened.</li>\n";
			die($this->error_message);
		}
	}



	function printFile()	{
		if($this->is_open = 1)	{
			if($this->bytes = "e")
					$this->bytes = filesize($this->url);

			while(!feof($this->fp))	{
				$this->line_content = fgets($this->fp, $this->bytes);
				echo $this->line_content;
			}
		}

		else	{
			$this->error_message .= "<li>Could not print <b>$this->url</b>, file has not been opened.</li>\n";
			die($this->error_message);
		}
	}



	function closeFile()	{
		if($this->is_open = 1)	{
			@fclose($this->fp) or $this->error_code = 4;

			if($this->error_code = 4)	{
				$this->error_message = "<p>\n<font color=\"red\">Warning: Could not close <b>$this->url</b>. <small><small><i>[Code 4]</i></small></small></font>";
				die($this->error_message);
			}
		}

		else	{
			$this->error_message .= "<li>Could not close <b>$this->url</b>, file is not open.</li>\n";
			die($this->error_message);
		}
	}


}
?>

Code:
[SIZE=1]Errors Returned[/SIZE]
Warning: fgets(): supplied argument is not a valid File-Handle resource in c:\program files\easyphp\www\getFile.php on line 55

Warning: feof(): supplied argument is not a valid File-Handle resource in c:\program files\easyphp\www\getFile.php on line 56

I know its messy, but can you sort through it?
 
Last edited:
as i see, you use windows...
try editing
fopen($this->url, "r")
to
fopen($this->url, "rb")
 
:eek: I feel stupid now...

<edit>
Forgot to tell you all what it was, look at the if's and you'll see the major problem. :eek: Can't believe I missed that...
 
Last edited:
Back
Top