Well, this one seems quite simple, and it is. All you have to do to download a file to your server is:
file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip"));
Only there is one problem. What if you have a large file, like 100mb. Then, you will run out of memory, and not be able to download the file.
What I want is a way to write the file to the disk as I am downloading it. That way, I can download bigger files, without running into memory problems.
A PHP 4 & 5 Solution:
readfile() will not present any memory issues, even when sending large files, on its own. A URL can be used as a filename with this function if the fopen wrappers have been enabled.
http://php.net/manual/en/function.readfile.php
Try using cURL
I'm not sure but I believe with the
CURLOPT_FILE
option it writes as it pulls the data, ie. not buffered.I use this to download file
Use a simple method in php
copy()
Note: if the destination file already exists, it will be overwritten
PHP copy() Function
Special Note: Don't forget to set permission 777 for the destination folder