Jump to content

[SOLVED] download image


maddogandnoriko

Recommended Posts

I have a function that downloads an image via curl. If the image is not available the page is an html page stating the image is not available. How can I check to see if the url to download is an image or the html page?

 

Thank you,

            maddogandnoriko

 

function LoadImageCURL($save_to){
	$ch = curl_init($this->source);
	$fp = fopen($save_to, "wb");

	// set URL and other appropriate options
	$options = array(CURLOPT_FILE => $fp,
									 CURLOPT_HEADER => 0,
									 CURLOPT_FOLLOWLOCATION => 0,
									 CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)

	curl_setopt_array($ch, $options);

	$result=curl_exec($ch);
	curl_close($ch);
	fclose($fp);
	return $result;
}

Link to comment
https://forums.phpfreaks.com/topic/153203-solved-download-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.