I want to "proxy" a file located on a remote server (let's call it Server B) and force its download to the visitor, from Server A.
Only Server A can access the ressource on Server B (IP address secured). The ressource can weight up to a few gigabytes.
Here is my code so far:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: chunked');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
$stream = fopen('php://output', 'w');
$ch = curl_init($ruri);
curl_setopt($ch, CURLOPT_READFUNCTION, function($ch, $fd, $length) use ($stream) {
return fwrite($stream, fread($fd, $length));
});
curl_exec($ch);
curl_close($ch);
It works partially.
Problem number 1:
Problem number 2:
Please note: