Download Remote File with PHP to Server and finally output to browser

Shown below is the code to download a remote file with PHP and save to the server and finally output to browser using cURL and readfile



  1. Since the file is downloaded to the server first before outputting to the browser, it consumes time, bandwidth & server space.
  2. When downloading large files, the script may exhaust the memory limit and is prone to timeout.