The given URL returns an "unknown host" error.
As from your code, you are not doing any error handling. Suppose the
- 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
you are getting the proper error message already.
file_get_contents()will give you all needed control to handle