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

 

Limitations:

  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.

3 Responses

  1. aallisfreehere.blogspot.com November 10, 2013 / 7:50 PM

    Well this is a good think, its not downloading the whole parts so i don’t need much space for serer , i can hotlink them, that’s way i can host 1tb and hot link via a 10gb vps.
    Awesome.
    But the problem is file is saving by “filename.zip” in this case .
    Can you help me by that?

    Thanks in advance.
    aallisfreehere.blogspot.com

    • Mithun John Jacob November 11, 2013 / 12:06 PM

      You can change the Line 4 to $file = "your-filename.zip";

      In the current code, it just saves the file using filename in the file URL.

  2. Fauzi April 2, 2014 / 6:28 PM

    Great!!
    Thanks for Sharing

Leave a Reply

Your email address will not be published. Required fields are marked *