Need php script to download a file on a remote server and save locally

Posted by bigLarry on Stack Overflow See other posts from Stack Overflow or by bigLarry
Published on 2010-12-21T21:44:25Z Indexed on 2010/12/21 21:54 UTC
Read the original article Hit count: 125

Filed under:

Trying to download a file on a remote server and save it to a local subdirectory.

The following code seems to work for small files, < 1MB, but larger files just time out and don't even begin to download.

<?php

 $source = "http://someurl.com/afile.zip";
 $destination = "/asubfolder/afile.zip";

 $data = file_get_contents($source);
 $file = fopen($destination, "w+");
 fputs($file, $data);
 fclose($file);

?>

Any suggestions on how to download larger files without interruption?

© Stack Overflow or respective owner

Related posts about php