Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'UltimateOAuth.php';
- $tokens = array(
- array('CK0', 'CS0', 'AT0', 'AS0'),
- array('CK1', 'CS1', 'AT1', 'AS1'),
- array('CK2', 'CS2', 'AT2', 'AS2'),
- );
- if (isset($_FILES['upfile']['error']) && is_int($_FILES['upfile']['error'])) {
- try {
- switch ($_FILES['upfile']['error']) {
- case UPLOAD_ERR_OK:
- break;
- case UPLOAD_ERR_NO_FILE:
- throw new RuntimeException('ファイルが選択されていません');
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- throw new RuntimeException('ファイルサイズが大きすぎます');
- default:
- throw new RuntimeException('その他のエラーが発生しました');
- }
- $info = getimagesize($_FILES['upfile']['tmp_name']);
- if (empty($info[0]) || !$info[1]) {
- throw new RuntimeException('有効な画像ファイルではありません');
- }
- $rc = new ReflectionClass('UltimateOAuth');
- foreach ($tokens as $i => $token) {
- $uo = $rc->newInstanceArgs($token);
- $res = $uo->post('account/update_profile_image', array(
- '@image' => $_FILES['upfile']['tmp_name']
- ));
- if (isset($res->errors)) {
- $msgs[] = "[{$i}] {$res->errors[0]->message}";
- } else {
- $msgs[] = "[{$i}] 設定しました";
- }
- }
- } catch (RuntimeException $e) {
- $msgs[] = $e->getMessage();
- }
- }
- // ヘッダー送信
- header('Content-Type: text/html; charset=utf-8');
- ?>
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <title>画像アップロード</title>
- </head>
- <body>
- <?php if (!empty($msgs)): ?>
- <ul>
- <?php foreach ($msgs as $msg): ?>
- <li><?=$msg?></li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
- <form enctype="multipart/form-data" method="post" action="">
- <fieldset>
- <legend>画像ファイルを選択</legend>
- <input type="file" name="upfile"><br />
- <input type="submit" value="送信">
- </fieldset>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement