Skip to content
WJunction - Webmaster Forum

(API) Filesonic DownLoad Plugin!

Status
Not open for further replies.

saninokia

Experienced Member
929
2010
71
just made it becoz someone me pm about it....

PHP:
<?php  
$filespath = dirname(__FILE__)."/files/";
$link = "http://www.filesonic.com/file/JHMyF1L"; 

$filename = getfsofilename($link); 
$link = getfsolink($link); 
$saveto = $filespath . $filename; 
echo "<b>Downloading</b> ..........</br><b>Filename:</b> $filename</br><b>Link:</b> $link ....<br />"; 
curldlfile($link, $saveto);

function getfsofilename($link) 
{ 
    $user = "fsc user"; // 
    $pass = "fsc pass"; // 
    $page = $link; 
    $id = explode("/", $page); 
    $id = trim($id[4]); 
    $apicall = "http://api.filesonic.com/link?method=getDownloadLink&u=$user&p=$pass&ids=$id"; 
    $page = file_get_contents($apicall); 
    preg_match('#\"filename\":\"(.*)\",\"url\"#', $page, $match1); 
    $filename = $match1[1]; 
    return $filename; 
}

function getfsolink($link) 
{ 
    $user = "fsc user"; // 
    $pass = "fsc pass"; // 
    $page = $link; 
    $id = explode("/", $page); 
    $id = trim($id[4]); 
    $apicall = "http://api.filesonic.com/link?method=getDownloadLink&u=$user&p=$pass&ids=$id"; 
    $page = file_get_contents($apicall); 
    preg_match('#\"url\":\"(.*)\"}}},#', $page, $match); 
    $linksid = $match[1]; 
    $link = str_replace("\/","/",$linksid); 
    return $link; 
}

function curldlfile($link, $saveto) 
{ 
    $handle = fopen($saveto, 'w'); 
    if ($handle) 
    { 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $link); 
        curl_setopt($ch, CURLOPT_FILE, $handle); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); 
        curl_exec($ch); 
        curl_close($ch); 
        fclose($handle); 
    } 
    else 
    { 
        echo "<br />Could not download $link. Is your 'files' folder chmodded to 777?"; 
        exit(); 
    } 
}
?>



For php uploader:

curl downloa function:​
PHP:
function curldlfile($link, $saveto)
{
    $handle = fopen($saveto, 'w');
    if ($handle)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $link);
        curl_setopt($ch, CURLOPT_FILE, $handle);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
        curl_exec($ch);
        curl_close($ch);
        fclose($handle);
    }
    else
    {
        echo "<br />Could not download $link. Is your 'files' folder chmodded to 777?";
        exit();
    }
}

Get Filename:​

PHP:
function getfsofilename($link)
{
    $user = "fsc username";
    $pass = "fsc password";
    $page = $link;
    $id = explode("/", $page);
    $id = trim($id[4]);
    $apicall = "http://api.filesonic.com/link?method=getDownloadLink&u=$user&p=$pass&ids=$id";
    $page = file_get_contents($apicall);
    preg_match('#\"filename\":\"(.*)\",\"url\"#', $page, $match1);
    $filename = $match1[1];
    return $filename;
}

Get Filelink:​

PHP:
function getfsolink($link)
{
    $user = "fsc username";
    $pass = "fsc password";
    $page = $link;
    $id = explode("/", $page);
    $id = trim($id[4]);
    $apicall = "http://api.filesonic.com/link?method=getDownloadLink&u=$user&p=$pass&ids=$id";
    $page = file_get_contents($apicall);
    preg_match('#\"url\":\"(.*)\"}}},#', $page, $match);
    $linksid = $match[1];
    $link = str_replace("\/","/",$linksid);
    return $link;
}

PHP:
$filename = getfsofilename($link);
$link = getfsolink($link);
$saveto = $filespath . $filename;
echo "<b>Downloading</b> ..........</br><b>Filename:</b> $filename</br><b>Link:</b> $link ....<br />";
curldlfile($link, $saveto);
 
Last edited:

9 comments

no,you need to save the file its just returning the download link,just save it using fopen.i configured it for php uploader which is in my lapy,if anyone still getting problem in configuring for his own use,reply me,i will do it.
 
well, your title say Filesonic DownLoad Plugin!

most users will just copy the code and will say will not work, if this is a plugin for a script you should say in your post
 
thread updated with single page download and php uploader support.just copy paste the single page plugin,it will work,just change the link and user,password.and use php uploader plugin carefully to keep it working.
 
You can fetch filename and link in 1 api-call.
Now you're slowing yourself down and causing more work for the FileSonic Api..
 
first time made api system,thx for your advice,i tried with 1 apicall but not working 2 return value using 1 apicall.
 
In that case; good job :)
You can return an array containing multiple values.
PHP:
function api_call(){
 // ...
 $return = array();
 $return[] = $filename;
 $return[] = $link;

 return $return;
}
 
Status
Not open for further replies.

About the author

S
Experienced Member · Joined
.::. Affordable & Reliable IT Services .::.
929
Messages
71
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom