Downloading big files and writing it locally

前端 未结 2 1110
长发绾君心
长发绾君心 2021-02-11 07:43

which is the best way to download from php large files without consuming all server\'s memory?

I could do this (bad code):

$url=\'http://server/bigfile\'         


        
2条回答
  •  无人及你
    2021-02-11 08:20

    You can use curl and the option CURLOPT_FILE to save the downloaded content directly to a file.

    set_time_limit(0);
    $fp = fopen ('file', 'w+b');
    $ch = curl_init('http://remote_url/file');
    curl_setopt($ch, CURLOPT_TIMEOUT, 75);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    

提交回复
热议问题