I am creating a download script that will allow me to allow users to download files that may be sitting on my server locally or on a remote server. In both cases, I do not want the user to find out the original file location.
In the case of my file being on my server, its easy:
$data = file_get_contents('/local/path');
$name = 'myphoto';
force_download($name, $data); //codeigniter
However, for remote files, if I do this:
$data = file_get_contents('/remote/path');
$name = 'myphoto';
force_download($name, $data);
It will download to my server first, which is going to delay the download for the user.
Is there a way I can stream any file somehow through my server to the user? So it starts downloading straight away? Possible?
Look at fpassthru: it’ll take a bit more than what you have, but it should do what you want.
You’ll want something like this: