public function savephoto($path, $thumb = true)
{
$photo_url = $this->photo($thumb);
if (!$photo_url) {
return false;
}
$req = new Request($photo_url, $this->config);
$req->sendRequest();
if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
$image = $req->getResponseBody();
} else {
$ctype = $req->getResponseHeader("Content-Type");
$this->debug_scalar("*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '{$ctype}'");
if (substr($ctype, 0, 4) == 'text') {
$this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n");
}
return false;
}
$fp2 = fopen($path, "w");
if (!$fp2) {
$this->logger->warning("Failed to open [{$path}] for writing at " . __FILE__ . " line " . __LINE__ . "...<BR>");
return false;
}
fputs($fp2, $image);
return true;
}