Download File to server from URL

后端 未结 12 1413
旧巷少年郎
旧巷少年郎 2020-11-22 04:05

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(\         


        
12条回答
  •  萌比男神i
    2020-11-22 04:16

    Try using cURL

    set_time_limit(0); // unlimited max execution time
    $options = array(
      CURLOPT_FILE    => '/path/to/download/the/file/to.zip',
      CURLOPT_TIMEOUT =>  28800, // set this to 8 hours so we dont timeout on big files
      CURLOPT_URL     => 'http://remoteserver.com/path/to/big/file.zip',
    );
    
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    curl_exec($ch);
    curl_close($ch);
    

    I'm not sure but I believe with the CURLOPT_FILE option it writes as it pulls the data, ie. not buffered.

提交回复
热议问题