How to save a remote file to disk with PHP

Josh Sherman
1 min read
Software Development 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.

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

Related Articles