How to save image from PHP URL?

Spread the love

Sometimes, we want to save image from PHP URL.

In this article, we’ll look at how to save image from PHP URL.

How to save image from PHP URL?

To save image from PHP URL, we can call file_put_contents.

For instance, we write

$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));

to call file_put_contents with the $img string to save the file to the $img path.

And we call file_get_contents to get the content of the image $url and use the returned file object as the 2nd argument.

Conclusion

To save image from PHP URL, we can call file_put_contents.

Leave a Reply

Your email address will not be published. Required fields are marked *