Saving a File or Webpage using PHP

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

Sometimes you want your PHP script to grab a text file or other external resource and save it locally.

Here is my simple function for doing just that.

function save_external_resource($resource, $filename){
$data = fopen($resource, 'r');
file_put_contents($filename, $data);

You can save any kind of resource from anywhere on the web that you have access to and save it locally.

For large files you may need to edit your php.ini and increase the resource limits and max execution time.

Tags: edmondscommerce