Uploading to FileSonic Using cURL

Status
Not open for further replies.

Gaurav

Active Member
641
2010
104
0
Announced in CB to release it and here it is.

Note: It is NOT for sBorg or phpUploader or Yawn's Script! It's in cURL and since those scripts use cURL to upload, you can get an idea how to port it to one of the scripts mentioned above. Without any delay, here we go:

PHP:
function uploadFiSO($x){
    if(!file_exists(dirname(__FILE__).'\fisocookie.txt'))
    {
        //Login if there is no cookie
        $val = postHost("http://www.filesonic.in/user/login", "email=$username&redirect=%2F&password=$password","", 'fisocookie.txt');
    }
    
    $cook = file_get_contents('fisocookie.txt');

    preg_match('/PHPSESSID.*/', $cook, $match);
    $sessionID = trim(str_replace('PHPSESSID', '', $match[0]));

    $millisec = round((microtime(true) * 1000.0));
    $random = rand(0,90000);

    $url = 'http://s115.filesonic.in/?X-Progress-ID=upload_'.$millisec.'_'.$sessionID.'_'.$random;

    $post = array('upload[]' => "@$x");

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, trim($url));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'\fisocookie.txt');
    //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); //Damn HTTP Error 417
    $result = curl_exec($ch);
    if(curl_errno($ch)){
    echo "ERROR - " . curl_error($ch);
    }
    curl_close($ch);

    $result = postHost('http://www.filesonic.in/upload-completed/upload_'.$millisec.'_'.$sessionID.'_'.$random, '',dirname(__FILE__).'\fscookie.txt');

    preg_match('/F[0-9]+/', html_entity_decode($result), $match);

    echo 'http://www.filesonic.com/file/'.str_replace('F','',$match[0]).'/'.$x;
}

function postHost($url, $data, $cookie, $storCook = null){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if($cookie != "")
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    if($data != ""){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    if(isset($storCook)){
        curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'\\'.$storCook);
        curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'\\'.$storCook);
    }
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); 
    $page = curl_exec($ch);
    curl_close($ch);

    return $page;

}
$x is the filename of the file to be uploaded. If you have any problems, do post and I'll try my best to sort it out :)

Usage: Copy paste the code above in a PHP file and then call it like this
PHP:
uploadFiSO('/path/to/file');

Regards,
gunda316
 
Last edited:
71 comments
@Netguy: knew enough JavaScript to find out how FSC generated random numbers ;) always had in mind I had to look for time function.
 
Well, its not on sale anymore and probably never will be again. I requested the thread to be deleted and hence it didn't come up in the search results.
 
Hello ! I've trying to use the script but I couldn't.. I've parse it in an php file and execute it but it don't work :(

Someone can explain to me what I should do to use it correctly ?

I change the password and the login but nothing..
 
Status
Not open for further replies.
Back
Top