Curl problem

Hi,
I’m having a problem getting a curl to work on a thumbnail script I have.


<?php
     
    $domain = $_SERVER['HTTP_HOST'];

    $fullimageurl = "http://$domain/images/BCANFALL.JPG";
    $fullimageurl2 = "http://$domain/images/noimagefound.jpg";

    $c = curl_init($fullimageurl);
    if (curl_getinfo($c, CURLINFO_HTTP_CODE) === 200) {
    $imagesurl = $fullimageurl;
    } elseif (curl_getinfo($c, CURLINFO_HTTP_CODE) === 404) {
    $imagesurl = $fullimageurl2;
    } else{
    $imagesurl = $fullimageurl2;
    }
    curl_close($c);

?>

The problem is that the fullimageurl does not exist and should error with the 404 above, but it doesn’t. All the other files that do exist come up under the else and not under the 200 OK part. I have no clue what I am doing wrong and see no error with the above.

Thanks,
Kevin

You need to call curl_exec before you can call curl_getinfo. Also, before calling curl_exec, you must set CURLOPT_RETURNTRANSFER to true otherwise curl_exec will write the image’s binary data (or the content of the 404 page) directly to the browser.

<?php
	$domain = $_SERVER['HTTP_HOST'];
	$fullimageurl = "http://$domain/images/BCANFALL.JPG";
	$fullimageurl2 = "http://$domain/images/noimagefound.jpg";
	$c = curl_init($fullimageurl);
	curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
	curl_exec($c);
	$http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
	curl_close($c);
	var_dump($http_code);
?>

Thanks a million!
Trying it now!

100% what I was looking for!!! Thanks!