How to save a remote file to disk with PHP

You may already be familiar with file_get_contents() for reading the contents
of a local file but did you know that you can use it to read the contents of a
remote file or site? You can then use file_put_contents() to write the file’s
contents back to disk:

file_put_contents('./some/local/file', file_get_contents('http://phpave.com'

Both functions are binary safe so you should be fine to work with files that
are not simply full of ASCII text.

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.