Hello all,

I'm trying to use the LinkShare Link Locator REST API, to get banner ads imported to my database. The problem is that LinkShare doesn't always have the correct image sizes listed, and I need them to fit in my site correctly. To overcome this, I've tried to use PHP's getimagesize function, but the height and width are not returned.
Please see below, these are the relevant parts of my script:

//script part
        $feed     = simplexml_load_file("http://lld2.linksynergy.com/services/restLinks/getBannerLinks/{$token}/{$mid}/{$cat}/{$startdate}/{$enddate}/{$size}/{$campaignID}/{$page}");
        $children = $feed->children('http://endpoint.linkservice.linkshare.com/');
        $entries  = $children->return;
        foreach ($entries as $entry) {
			$details = $entry->children('http://endpoint.linkservice.linkshare.com/');
			list($realwidth,$realheight) = remote_filesize($details->imgURL); 
			echo "<a href=\"{$details->clickURL}\" target=\"_NEW\">";
			echo "<img src=\"{$details->imgURL}\" border=\"0\" height=\"{$realheight}\" width=\"{$realwidth}\" title=\"{$details->name}\" alt=\"{$details->name}\" />";
			echo "</a><img border=\"0\" height=\"1\" width=\"1\" src=\"{$details->showURL}\" /><br>\n";
		}

//function:
 function remote_filesize ($url) {
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $data = curl_exec($ch);
   curl_close($ch);
   $filename = "temp." . mt_rand();
   $fp = @fopen($filename, "w+");
   fwrite($fp, $data);
   fclose($fp);
   $info = getimagesize($filename);
   @unlink($filename);
   return $info;
}

    nevermind, as soon as I posted this I saw something wrong...<img border="0" height="1" width="1" src="" />. That src shouldn't be empty.
    Anyway, I found a curl function on PHP.net that follows all redirects, that this seems to work so far. http://www.php.net/manual/en/ref.curl.php#92848

      Write a Reply...