Page 1 of 1

Need help with a Curl issue

Posted: Wed Apr 14, 2010 5:27 pm
by ChrisF79
Greetings:

I have the following code to download some images off of the local Realtor MLS:

Code: Select all

			// Use Curl To Save The Files Locally //
			$save_to = $fullpath;
			$mh = curl_multi_init();
			foreach ($urls as $i => $url) {
			    $g=$save_to.basename($url);
			    if(!is_file($g)){
			        $conn[$i]=curl_init($url);
			        $fp[$i]=fopen ($g, "w");
			        curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
			        curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
			        curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60);
			        curl_multi_add_handle ($mh,$conn[$i]);
			    }
			}
			do {
			    $n=curl_multi_exec($mh,$active);
			}
			while ($active);
			foreach ($urls as $i => $url) {
		    curl_multi_remove_handle($mh,$conn[$i]);
		    echo '<p>$i = ' . $i . '<br />$mh = ' . $mh . '<br />$conn[$i] = '.$conn[$i].'</p>';
			    curl_close($conn[$i]);
			    fclose ($fp[$i]);
			}
			curl_multi_close($mh);
When that runs, I'm getting the errors:

Code: Select all

Warning: curl_close(): supplied argument is not a valid cURL handle resource in /home/chrisfar/public_html/lister/process_listing.php on line 652

Warning: fclose(): supplied argument is not a valid stream resource in /home/chrisfar/public_html/lister/process_listing.php on line 653

Warning: curl_multi_remove_handle() expects parameter 2 to be resource, null given in /home/chrisfar/public_html/lister/process_listing.php on line 650
I have that statement in there to output what's in the variables and when it ran last, this is what it spit out:

Code: Select all

$i = 1
$mh = Resource id #7
$conn[$i] =
So it's not giving me a $conn[$i] which is why I'm getting the error, correct? The weird thing is though, it is actually downloading the image somehow. Any idea what's going on and how I can fix it?

Thanks so much in advance!