Answer the question
In order to leave comments, you need to log in
How to download a file to the server bypassing the buffer?
How to direct a file download from a third-party server directly to a file? at the moment, downloading the file is implemented through CURL, while the file is written in "portions" of 20+ mb. I would like to somehow reduce these "portions", perhaps by somehow limiting the size of the buffer.
$fp = fopen($filename, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($cp, $data) use ($fp) { return fwrite($fp, $data); });
curl_exec($ch);
curl_close($ch);
fclose($fp);
Answer the question
In order to leave comments, you need to log in
just like you write to a file in your code,
which prevents fopen from requesting the file and specifying the url in $filename
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question