主人MediaFire API PHP开发 [英] Mediafire API PHP Development
问题描述
我发现主人MediaFire API几天前。
I found mediafire API few days ago.
http://developers.mediafire.com
和我搜索在互联网上反正是有使用API,使上传文件的Web应用程序,以主人MediaFire帐户。不幸的是我没有发现任何东西。是否有人知道如何创建与主人MediaFire API和PHP文件上传的Web应用程序。
and I search over the internet is there anyway to make a web app for upload files to mediafire account using API. Unfortunately I haven't found anything. Is anybody know how to create a file uploading web app with mediafire API and PHP.
推荐答案
首先获得一个会话令牌。
First get a session token.
$apikey = 'YOUR API KEY HERE';
$appid = 'APPLICATIONID';
$email = 'your@email.com';
$passwd = 'PASSWORD';
$params = http_build_query(array(
'email' => $email,
'password'=> $passwd,
'application_id' => $appid,
'signature' => sha1("$email$passwd$appid$apikey"),
'response_format' => 'json'
));
$fp = fopen('https://www.mediafire.com/api/user/get_session_token.php?'.$params, 'r');
$json = stream_get_contents($fp);
$obj = json_decode($json);
fclose($fp);
$session = $obj->response->session_token;
这个新的 $会议
键上传文件现在。
$filecontents = file_get_contents("/path/to/file");
$filesize = strlen($filecontents);
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=> "x-filename : ANYFILENAMEYOUWANT\r\n".
"x-filesize : $filesize\r\n"
)
);
$context = stream_context_create($opts);
$params = http_build_query(array(
"session_token" => $session
));
$fp = fopen('http://www.mediafire.com/api/upload/upload.php?'.$params, 'r', false, $context);
fwrite($fp, $filecontents);
$result = stream_get_contents($fp);
fclose($fp);
重要提示:请亲自试一试。我没有测试它。刚才看到的API,并写了这个code。因此,它不会在第一次去工作。你需要修改,以使其发挥作用。
Important Note: Please try it yourself. I have not tested it. Just saw the API and wrote this code. So it wont work on first go. You'll need to modify to make it work.
这篇关于主人MediaFire API PHP开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!