I have a script that can find images from a URL, given by the user.
So for input string: “http://www.google.com/”,
I use something like
$html = file_get_html ( $url );
if ($html->find ( 'img' )) {....}
It brings the result as ‘http://www.google.com/images/srpr/logo3w.png’.
But if the user inputs a string “http://www.google.com/images/srpr/logo3w.png”. There is no img tag. URL is valid, but code fails. How can this case be included in the code?
The best way to do this would be to perform a HEAD request and check the content type to see if the URL corresponds to an image. If it’s an image, then do whatever you want with it, but if it’s an HTML page, then use your other code.