How to download remote file without read it

I want to download a remote file to the CI folder without reading it to a string.
I can use $string = read_file($file); and then put the string in a file, but can i do this without read in the memory? How I can optimize this?

Well theres no way to really skip the memory part, but you can reduce the ammount of memory used. So instead of reading the enitre file into memory and then save it you can read a small portion at a time, saving it to disk along the way.

function save_file($inPath,$outPath)
    $in=    fopen($inPath, "rb");
    $out=   fopen($outPath, "wb");
    while ($chunk = fread($in,8192))
        fwrite($out, $chunk, 8192);


[eluser]Burak Guzel[/eluser]
Look into cURL, and the CURLOPT_FILE option. I would assume it saves directly into the file instead of storing in memory.

Found a related question here:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.