I am trying to find a solution to get directly the file like wget does instead of reading from the stream and writing to another file, but I am not sure if this is possible.
Any suggestions?
I am trying to find a solution to get directly the file like wget does instead of reading from the stream and writing to another file, but I am not sure if this is possible.
Any suggestions?
is a one liner too ;-)
The only issue with above code could be with very large files: copy could be better in that case, but see also http://www.php.net/manual/en/function.copy.php#88520
Some testing needed...
With
CURLOPT_FILE
you can write some filestream direct into an open filehandle (see curl_setopt).Edit based on your comments:
If you want a oneliner or want to use wget call it through exec() or system() like so:
Edit for later reference:
All three methods have nearly equal runtime and memory usage.
Use whatever fits best to your environment.
And now write $c to local file ...
I also found copy which allows to copy a file from an url directly to your disk and is a oneliner without the complexity of curl or the need to create an empty file where to transfer the content of file_get_contents.