카테고리 없음

왜 두번 실행되지??

행복을전해요 2020. 3. 31. 00:16
<?php
include_once("./lib/xmlrpc.inc");
?>


<form method="POST" style="position:relative;">
     
    <input type="text" name="user_id" placeholder="사용자 ID를 입력하세요" style="position:relative;width:100%;padding:10px;font-size:1.02em;margin-bottom:15px;">
    <!--<input type="text" name="blogid" placeholder="블로그 ID를 입력하세요" style="width:100%;padding:10px;font-size:1.02em;margin-bottom:15px;">-->
    <input type="text" name="password" placeholder="API 값을 입력하세요" style="width:100%;padding:10px;font-size:1.02em;margin-bottom:15px;">
    <input type="text" name="title" placeholder="제목을 입력하세요" style="width:100%;padding:10px;font-size:1.02em">
    <p>
	<textarea name="content" ></textarea>
   
    </p>
    <input type="submit" value="글을 작성합니다" style="font-size:1.01em;width:230px;height:40px;background-color:#fff;border:1px solid #ddd;">
</form>

<?php
function newPost($description) {
  $title=$_POST["title"];
  //$description = "desc";
  $user_id=$_POST["user_id"];
  //$blogid=$_POST["blogid"];
  $content=$_POST["content"];
   $g_blog_url = "https://api.blog.naver.com/xmlrpc";
   $password = $_POST["password"]; // 불로그 글쓰기API에서 받은 암호
   $publish = true;
   $client = new xmlrpc_client($g_blog_url); 
   $client->setSSLVerifyPeer(false); 
   $GLOBALS['xmlrpc_internalencoding']='UTF-8'; 

   $struct = array( 
   'title' => new xmlrpcval($title, "string"), 
   'description' => new xmlrpcval($description, "string")
   ); 
   $f = new xmlrpcmsg("metaWeblog.newPost", 
   array( 
   new xmlrpcval($blogid, "string"), 
   new xmlrpcval($user_id, "string"), 
   new xmlrpcval($password, "string"), 
   new xmlrpcval($struct, "struct"), 
   new xmlrpcval($publish, "boolean") 
   ) 
   ); 

   $f->request_charset_encoding = 'UTF-8';
   return $response = $client->send($f);
}


//네이버블로그 이미지 업로드
function upload_image($fpath) {
 
   $api_url = "https://api.blog.naver.com/xmlrpc"; 
   $blog_user = $_POST["user_id"]; //네이버아이디
   $blog_passwd = $_POST["password"]; //블로그 글쓰기API에서 받은 암호
   
   $imgbit = file_get_contents($fpath, FILE_BINARY);
   $img = new xmlrpcval(
   array (
   'bits' => new xmlrpcval($imgbit, 'base64'),
   'type' => new xmlrpcval('image/jpeg', 'string'),
   'name' => new xmlrpcval(basename($fpath), 'string')
   ), 'struct');
    $cfile1 = new CURLFile('11.jpg','image/jpeg');

   $c = new xmlrpc_client($api_url);
   //  $c->debug = true; // Uncomment this line for debugging info
   $c->setSSLVerifyPeer(false);

   $x = new xmlrpcmsg("metaWeblog.newMediaObject");
   $x->addParam(new xmlrpcval($blog_user, 'string'));
   $x->addParam(new xmlrpcval($blog_user, 'string'));
   $x->addParam(new xmlrpcval($blog_passwd, 'string'));
   $x->addParam($img);

   $c->return_type = 'phpvals';
   $r =$c->send($x, 3, 'https');
   if ($r->errno=="0") {
     return $r->val['url'];

   } else {
     echo "There was an error<pre>";
     print_r($r);
     echo "</pre>";
     return null;
   }
}
print "asdf";
print newPost("<img src=\"".upload_image("11.jpg")."\">");
?>