1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Yey! Curl upload problem

Discussion in 'PHP' started by ps3ubo, Apr 17, 2010.

  1. #1
    Hiya,

    anyone know whats up with my script? - i want it to upload to a site but its not doing anything.
    Shows this error Wystąpił błąd podczas wrzucania pliku. - meaning error with file upload

    
    <?php
    $url = "http://www.wrzuta.pl/pliki/dodaj";
    
    $filename = "audio.mp3";
    $cookiefile = "cookies.txt";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, "files_qnt=1&static=1&MAX_FILE_SIZE=157286400&file=".@$filename);
    
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $res = curl_exec($ch);
    echo $res;
    curl_close($ch);
    ?>
    
    PHP:
    If this cannot work - is there any other method to upload to this site? Perl maybe? :S
     
    ps3ubo, Apr 17, 2010 IP
  2. trickyshaun

    trickyshaun Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    nah .... You must use CURL option CURLOPT_UPLOAD
     
    trickyshaun, Apr 17, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    @ps3ubo

    <?php
    $url = "http://www.wrzuta.pl/pliki/dodaj";
    
    $cookiefile = "cookies.txt";
    
    //path to file you want to upload
    $data['file'] = '@C:\xampp\htdocs\audio.mp3'; 
    $data['MAX_FILE_SIZE'] = '157286400'; 
    //etc..
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $res = curl_exec($ch);
    echo $res;
    curl_close($ch);
    ?>
    PHP:
     
    danx10, Apr 17, 2010 IP
  4. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
  5. ps3ubo

    ps3ubo Peon

    Messages:
    204
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Works perfectly! and very fast upload ^_^ thanks!
     
    ps3ubo, Apr 18, 2010 IP