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,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    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.
    I can't really think of anything to write here now...


  •  

    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
    •