note 23741 added to function.fopen
| From: | web@php.net | Date: | Fri, 26 Jul 2002 12:23:19 +0000 |
| Subject: | note 23741 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33601@lists.php.net to get a copy of this message | ||
+------------------------------------+
| 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~~
--
http://www.php.net/manual/en/function.fopen.php
http://master.php.net/manage/user-notes.php?action=edit+23741
http://master.php.net/manage/user-notes.php?action=delete+23741
http://master.php.net/manage/user-notes.php?action=reject+23741