Imdb\Title::savephoto PHP Метод

savephoto() публичный Метод

Save the poster/cover image to disk
См. также: IMDB page / (TitlePage)
public savephoto ( string $path, boolean $thumb = true ) : boolean
$path string where to store the file
$thumb boolean get the thumbnail (100x140, default) or the bigger variant (400x600 - FALSE)
Результат boolean success
    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;
    }