Imdb\Person::savephoto PHP Method

savephoto() public method

Save the photo to disk
See also: IMDB person page / (Main page)
public savephoto ( $path, $thumb = TRUE, $rerun = FALSE ) : boolean
return boolean success
    public function savephoto($path, $thumb = TRUE, $rerun = FALSE)
    {
        $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) {
            $fp = $req->getResponseBody();
        } else {
            if ($rerun) {
                $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '" . $req->getResponseHeader("Content-Type") . "'<BR>");
                return FALSE;
            } else {
                $this->debug_scalar("<BR>Initiate second run for photo '{$path}'<BR>");
                return $this->savephoto($path, $thumb, TRUE);
            }
        }
        $fp2 = fopen($path, "w");
        if (!$fp || !$fp2) {
            $this->debug_scalar("image error...<BR>");
            return false;
        }
        fputs($fp2, $fp);
        return TRUE;
    }