加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Mediafire API PHP开发

发布时间:2020-12-13 13:31:46 所属栏目:PHP教程 来源:网络整理
导读:我几天前找到了mediafire API. http://developers.mediafire.com 我在互联网上搜索是为了使用API??创建一个上传文件到mediafire帐户的网络应用程序.不幸的是我没有找到任何东西.有人知道如何使用mediafire API和PHP创建上传Web应用程序的文件. 首先获取会话
我几天前找到了mediafire API.

http://developers.mediafire.com

我在互联网上搜索是为了使用API??创建一个上传文件到mediafire帐户的网络应用程序.不幸的是我没有找到任何东西.有人知道如何使用mediafire API和PHP创建上传Web应用程序的文件.

首先获取会话令牌.
$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;

现在用这个新的$session键上传一个文件.

$filecontents = file_get_contents("/path/to/file");
$filesize = strlen($filecontents);
$opts = array(
  'http'=>array(
    'method'=>"POST",'header'=> "x-filename : ANYFILENAMEYOUWANTrn".
               "x-filesize : $filesizern"
  )
);
$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并编写了这段代码.所以它不会在第一次工作.您需要进行修改才能使其正常工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读