Đầu tiên nhận mã thông báo phiên.
$apikey = 'YOUR API KEY HERE';
$appid = 'APPLICATIONID';
$email = '[email protected]';
$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;
Bây giờ với khóa mới này $session
tải lên tệp.
$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);
Lưu ý quan trọng: Hãy thử nó cho mình. Tôi chưa thử nghiệm nó. Chỉ cần nhìn thấy API và viết mã này. Vì vậy, nó sẽ không làm việc trên đi đầu tiên. Bạn sẽ cần phải sửa đổi để làm cho nó hoạt động.
Nguồn
2012-12-27 10:51:32
Bạn đã trả lời cho câu hỏi của riêng bạn: http://developers.mediafire.com/index.php/REST_API và cụ thể hơn: http://developers.mediafire.com/index.php/REST_API#upload – Supericy