-1

I would like to implement a PHP web page that, given a certain URL, is going to sniff some images from that page. Do to so, I need :

1) to access the html source-code of that page and find out the URLs of the images I want.

2) to download these images on my FTP

I don't know how to do these two tasks, I guess I will have to use third party libraries, but this is the first time I need to do so and I am not sure. Any advices ?

Thank you.

phenetas
  • 109
  • 7
  • 1
    Take a look to the PHP DOMDocument. I think it could help you. [link](http://php.net/manual/es/class.domdocument.php) – Peter Aug 18 '15 at 23:28

2 Answers2

0

This is actually quite a simple task in PHP:

  1. Use file_get_contents() to fetch the HTML from any random page (cURL would work too).
  2. Using DOMDocument, find all img tags inside the page (see getElementsByTagName() method)
  3. Extract the src attribute from each node.
  4. Download the images somewhere with cURL.
  5. Use the FTP functions to upload them to your server (or use a library like this one).
Anonymous
  • 10,357
  • 3
  • 37
  • 49
-1

Did you mean grab html page's images and download them and then upload these images to your own FTP server?

If I catch on you correctly, this task will be completed by plain PHP code, no need of third party libraries.

  1. Use preg_match_all to match all images out

  2. Download them(use curl or file_get_content)

  3. upload them to your FTP server, you can simply use curl again, put that image you downloaded above(you don't need save image in your PHP located machine, it is a File Stream in memory) in POST request body then send the request. Or upload image using FTP related functions(find that function in PHP net Document)

You need do step 2 and 3 in a loop basing on data generated from step 1.

Tell me if you need help about them.

Kevin Yan
  • 1,216
  • 11
  • 19