getElementsByTagName ignoring relative url

239 views Asked by At

hi i am using below code to extract few images whose size is bigger than 30 kb and it works just fine if the src in image tag is absoulte url but it fails if the src tag in img url is relative url as i am checking the size of the image i think it is unable to check relative url file. how i can make it check the size of relative as well as absolute url

     $websitelink='http://www.xyziiiii.com/im-giving-you-3-guesses-where-model-isabela-soncini-is-from';

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $websitelink);    
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 $result = curl_exec($ch);

 $doc = new DOMDocument();
 libxml_use_internal_errors(true);
 $doc->loadHTML($result); // loads your html
$tags = $doc->getElementsByTagName('img'); 
foreach ($tags as $tag) { 
 $data = get_headers($tag->getAttribute('src'),1); 
  if((intval($data["Content-Length"])/1024)>=30){ 
   $op7=''.$tag->getAttribute('src').'';
   echo  $op7;
 }}
1

There are 1 answers

6
Madara's Ghost On

Append the relative URL to the end of your original URL. It should be resolved correctly.