CURL Help Please!

Discussion in 'PHP' started by hostrs.com, Dec 4, 2009.

  1. #1
    Hey guys. I really need help. I have a script that needs to login and stream a file from a remote server. It logins in fine, but it outputs the file inside the browser with lots of weird symbols. How can I make it put the file up in zip format so that the user can download it right away, without the need to save it to server first. Thanks!!!!!!!!!

    Here is my script:
    $cookie_file_path = "cookie.txt"; 
    $useragent='Mozilla 5.0 ';
    $ch = curl_init();
    $LOGINURL = "http://mydomain.com/login.php";     
    $POSTFIELDS = 'user=test&pass=test&redirect=file.zip';
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$LOGINURL); 
    curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_REFERER, $reffer); 
    curl_setopt($ch, CURLOPT_HEADER,0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
    $result= curl_exec ($ch);
    echo $result;
    curl_close ($ch);
    Code (markup):
     
    hostrs.com, Dec 4, 2009 IP
  2. hostrs.com

    hostrs.com Peon

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Never mind. Found answers. Works like charm. Here is the code i added at bottom so that it streams the file:

     
    hostrs.com, Dec 4, 2009 IP
  3. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Surely if the file is considerably large, you would run out of memory since $file= curl_exec ($ch); loads the whole file into memory, doesn't it?
     
    szalinski, Dec 5, 2009 IP
  4. hostrs.com

    hostrs.com Peon

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your right. I did run into some problems. but got resolved. thanks
     
    hostrs.com, Dec 8, 2009 IP