w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
grab image using curl_exec not working on certain domain

The given URL returns an "unknown host" error.

As from your code, you are not doing any error handling. Suppose the following:

  • the server name is wrong (as the above url)
  • the server doesn't respond
  • the server gives an error (http 50x)
  • the link is not an image
  • the link is gone (http 40x)

you need to catch all of the above in order to be sure to actually got at least what you want before starting to save something to a file.

As from your try:

I have tried file_get_contents(), but it failed to work as well, code error -> php_network_getaddresses: getaddrinfo failed: Name or service not known.

you are getting the proper error message already. file_get_contents()will give you all needed control to handle such errors.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.