Need quick CURL help - only 10 days left to finish my project

Discussion in 'PHP' started by nastynappy, Oct 1, 2008.

  1. #1
    Dear friends.

    After wasting 2 whole days of my project time trying to figure out why it doesnt work, I came here for help.
    Please help me.

    My project is to make auto torrents uploader.
    but for some reasons, curl is not submitting the file upload form.

    I tried :

    	
    $file='@D:\Die_Lunikoff_Verschw__rung-Heil_Froh_2008.4421019.TPB.torrent';
     
        
        $ch = curl_init('http://mininova.org/upload');  
    	curl_setopt($ch, CURLOPT_COOKIEJAR, "./tmp/cookies");
    	curl_setopt($ch, CURLOPT_COOKIEFILE, "./tmp/cookies");
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('torrent'=>"$file",'name'=>'test value'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_REFERER, 'http://www.mininova.org/upload');
    
    	
    	
        $postResult = curl_exec($ch);
        curl_close($ch);
        print "$postResult"; 
    PHP:
    it just prints a blank page.

    But when I setup my own file uploader script on localhost similar to mininova, it uploads the file :( but not on mininova..
    Please help me.. there isnt any error on curl_errno ( returns 0 )

    But when I fetch the page using curl normally without submitting file upload form, it successfully fetches http://www.mininova.org/upload page.

    Please help me, I really need help, I need to finish my project :(
     
    nastynappy, Oct 1, 2008 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    I can see the obvious problem. I haven't looked for others.

    
    $file='@D:\Die_Lunikoff_Verschw__rung-Heil_Froh_2008.4421019.TPB.torrent';
    
    PHP:
    You need to escape the backslash.

    
    $file='@D:\\Die_Lunikoff_Verschw__rung-Heil_Froh_2008.4421019.TPB.torrent';
    
    PHP:
     
    Kaizoku, Oct 1, 2008 IP
  3. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your code is fine.

    Enabling these CURL options
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    PHP:
    reveals the problem:
    HTTP/1.1 417 Expectation Failed
    Connection: close
    Content-Length: 0
    Date: Wed, 01 Oct 2008 11:50:10 GMT
    Server: lighttpd/1.4.19
    Code (markup):
    This is, unfortunately, a known lighttpd bug (so yes, the problem is with the server).

    You can however fix your particular problem client-side, by overwriting the Expect-Header and setting it to an empty value:

    curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Expect: '));
    PHP:
    Please post back if this works.. but it should :)
     
    keyaa, Oct 1, 2008 IP
  4. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No mate.. the link to file is corrent, as I said above, i tested it on localhost and it works fine.

    Hmm , thanks bro, it worked. :)
    but.. it doesnt submit the form fields :s just shows a fresh new page :s
    it gives me : error number 26
     
    nastynappy, Oct 2, 2008 IP