Guest User

Untitled

a guest
Feb 6th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. $imageurl = "http://resimadres.jpg";
  2.  
  3. $PostTitle = "Yazı Başlığı";
  4. $PostContent = "Yazı içeriği"
  5. $PostTags = Array("Etiket 1,Etiket 2");
  6.  
  7. $PostCategoryID = 1; // Category ID
  8.  
  9.  
  10. // IMAGE Upload
  11.  
  12. $myFile = 'temp/' . rand(0,90000) . '-image.jpg';
  13. $content = file_get_contents($imageurl);
  14. if(!file_exists($myFile)){touch($myFile);}
  15. file_put_contents($myFile, $content);
  16.  
  17. $fh = fopen($myFile, 'r');
  18. $fs = filesize($myFile);
  19. $theData = fread($fh, $fs);
  20. fclose($fh);
  21. $client->debug = false;
  22. $params = array('name' => $myFile , 'type' => 'image/jpg', 'bits' => new IXR_Base64($theData), 'overwrite' => true);
  23. $res = $client->query('wp.uploadFile',1, $username, $password, $params);
  24. $clientResponse = $client->getResponse();
  25.  
  26. if(isset($clientResponse['faultCode'])){ die("İmaj dosyası yüklenemedi. Lütfen kontrol ediniz."); }
  27. unlink($myFile);
  28.  
  29. $thumbnail = $clientResponse['thumbnail'];
  30. $original_url = $clientResponse['url'];
  31. $thumbnail_id = $clientResponse['id'];
  32. // IMAGE Upload
  33.  
  34.  
  35. $params = xmlrpc_encode_request('wp.newPost', array(0,$username,$password, array('post_title' => $PostTitle,'post_content' => $PostContent,'post_status' => 'publish','post_thumbnail' => $thumbnail_id, 'comment_status' => 'open', 'terms_names' => array('post_tag' => $PostTags,'category' => "1" )) ),array('encoding'=>'UTF-8','escaping'=>'markup'));
  36. $ch = curl_init();
  37.  
  38. curl_setopt($ch, CURLOPT_URL, $url);
  39. curl_setopt($ch, CURLOPT_POST, TRUE);
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  42. curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  43.  
  44. $veri= curl_exec($ch);
  45. curl_close($ch);
  46.  
  47. echo "
  48. " . $veri . ' : ID Eklendi!
  49. ';
Add Comment
Please, Sign In to add comment