note 23741 deleted from function.fopen by alindeman
| From: | alindeman@php.net | Date: | Sat, 17 May 2003 21:05:45 +0000 |
| Subject: | note 23741 deleted from function.fopen by alindeman | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48261@lists.php.net to get a copy of this message | ||
Note Submitter: web at affenkrieger.de
+------------------------------------+
| addition to the GetWebObject class |
+------------------------------------+
the version above doesn't work with binary data, e.g. pictures
replace the fetch method with this one and all should work:
~~8<~~
function fetch()
{
$fp = fsockopen ($this->host, $this->port);
if(!$fp)
{ die("Could not connect to host.");}
$header_done=false;
$request = "GET ".$this->path." HTTP/1.0\r\n";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n";
$request .= "Host: ".$this->host."\r\n";
$request .= "Connection: Close\r\n\r\n";
$return = '';
fputs ($fp, $request);
$line = fgets ($fp, 128);
$this->header["status"] = $line;
while (!feof($fp))
{
if($header_done)
{
$line = fread ( $fp, 1024 );
$this->content .= $line;
}
else
{
$line = fgets ($fp, 128);
if($line == "\r\n")
{ $header_done=true;}
else
{
$data = explode(": ",$line);
$this->header[$data[0]] = $data[1];
}
}
}
fclose ($fp);
}
~~>8~~