Pulling images from a url when I ran into something I never had before. The header check returned a 403 error and although the images extensions were listed as .jpg they were returned as a application/octet-stream, and checking the content type returned text/html.
I have read the 403 "typically" is to prevent screen scrapping, but this is just on the images.
I found it odd that I could view the source of the web page, see the image src, and click on it and return the image to the browser, but not via code.
Is there a way to convert the image url into an actual image? I eventually want to pull height, width, size info from the images and save them to a folder on my server.
$html = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag){
$image_src = $tag->getAttribute('src');
echo get_headers($image_src, 1); //returns a 403 Forbidden Error
echo image_type_to_mime_type(exif_imagetype($image_src)); //returns application/octet-stream
$i = getimagesize($image_src);
var_dump($i); //returns bool(false)
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_NOBODY, true);
curl_setopt($c, CURLOPT_URL, $image_src);
curl_exec($c);
echo $content_type = curl_getinfo($c, CURLINFO_CONTENT_TYPE); //returns text/html
}