Title: lacking photos from external Url php
Tags: php;html;dom
Question: I am using server side for getting photos from external url. I am using simple php dom library for getting this as per SO suggestion. But I am lacking performance in this. I mean for some sites I am not able to get all the photos.
$url has the example external site which is not giving me all the images.

```  $url
  ="http://www.target.com/c/baby-baby-bath-bath-safety
  /-/N-5xtji#?lnk=nav_t_spc_3_inc_1_1";
  $html = file_get_contents($url);
  $doc = new DOMDocument();
  @$doc-&gt;loadHTML($html);
  $tags = $doc-&gt;getElementsByTagName('img');

  foreach ($tags as $tag) {
      echo $imageUrl = $tag-&gt;getAttribute('src');
   echo "<br /&gt;";
  }
```

Is this possible I can have functionality/accuracy similar to the option of Firefox

Firefox-> tools -> page info -> media 

I mean I just want to be more accurate for this as the existing library is not fetching all images. Also I tried file_get_content...which is also not fetching all the images.

Comment: I am not sure about using iframes in this scene. But I just want to get images from the external url to use in my bookmarklet. which will open as pop up at any website.

Comment: If you do an `echo $html;` you will notice that the HTML is non-existant. `hello,

We’re experiencing some technical difficulties, sorry for the inconvenience.` - This is probably to stop screen scraping from their end. Is it possible to use iframes for this?

Comment: ask them nicely and take copies if they say yes, and serve them locally.

Comment: Do you get a timeout (`max_execution_time`)?

Here is the accepted answer: You need to use regular expressions to get images' src. DOMDocument build all DOM structure in memory, You needn't it. When You get URLs, use ```file_get_contents()``` and write data to files. Also add ```max_execution_time``` if You'll parse many pages.

Comment for this answer: As per last suggestions by SO I will need to fetch images using server side scripting. For doing that either I will use file_get_contents or dom libraray. but problem is that it is not giving me images for almost all the images.The same script is working for other websites.
Comment for this answer: So Should I need to use curl here. because I am not able to get images using file_get_contents ?
Comment for this answer: Thanks Egor.. :)...Actually I am trying to make something similar to http://www.myregstry.com. Please have a look at ADD TO MY registry feature in it if get a chance...Thanks again
Comment for this answer: DOM library just convert string(HTML) to object model with their(objects) attributes(ex.: $html->img->src). Every object eat some memory, when You get all page in DOM library You get as many object as many tags on page. After that You search images and get only 1 attribute from them: src. Right way to find src from 1 step, from 1 string(HTML). Now some words about file_get_contents and timeouts. Maybe some host is too slow and your server think, that he can't take image. In this way You should get images via `cURL` functions
Comment for this answer: Yes, I think it's the best solution.

Here is another answer: ```
  Download images from remote server
```

```function save_image($sourcePath,$targetPath)
  { 

      $in  = fopen($sourcePath, "rb");
      $out = fopen($targetPath, "wb");
      while ($chunk = fread($in,8192))
      {
          fwrite($out, $chunk, 8192);
      }
      fclose($in);
      fclose($out);
  }

$src = "http://www.example.com/thumbs/thumbs-t2/1/ts_11083.jpg"; //image source
$target = dirname(__FILE__)."/images/pic.jpg"; //where to save image with new name
save_image($src,$target);
```

Comment for this answer: thanks for replying but I just want to fetch and show the images from teh external website then user wil choose the one and that will save on server.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:01/04/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><html><dom>', 'Title': 'lacking photos from external Url php', 'ViewCount': 175, 'id': 8724040, 'user_AboutMe': '', 'user_AccountId': 1077343.0, 'user_DisplayName': 'Rohit', 'user_Reputation': 19.0, 'user_Views': 20.0, 'user_id': 1075187.0}}