Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Post Download remote file and stream to user using cURL

    what this code does is to download a-large-file.zip from example.com and save to hard disk.

    instead of saving to hard disk, how do i stream the file to user?

    PHP Code:
    <?php
        $url  
    'http://www.example.com/a-large-file.zip';
        
    $path '/path/to/a-large-file.zip';
     
        
    $fp fopen($path'w');
     
        
    $ch curl_init($url);
        
    curl_setopt($chCURLOPT_FILE$fp);
     
        
    $data curl_exec($ch);
     
        
    curl_close($ch);
        
    fclose($fp);
    ?>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    You still need to save it to the hard disk (otherwise you're in danger of eating up all the ram OR getting a message from php about the memory being exhausted).

    Then you need to reopen it and in a loop fread it and print it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •