Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. $username = "ZX";
  2. $password = "ZX";
  3. $host = 'http://ZX.com/wp-json/wp/v2/media';
  4. $data = json_encode($data);
  5. $file = '/Users/xx.png';
  6. $imagedata = file_get_contents($file);
  7. $process = curl_init($host);
  8. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($process, CURLOPT_BINARYTRANSFER, TRUE);
  10. curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
  11. curl_setopt($process, CURLOPT_TIMEOUT, 50);
  12. curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
  13. curl_setopt($process, CURLOPT_POSTFIELDS, $data);
  14. curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type:image/png','Content-Disposition:attachment;filename='.$file));
  15. $return = curl_exec($process);
  16. print_r($return);
  17.  
  18. $data = array(
  19. "status" => "draft",
  20. "title" => "Photo media",
  21. "description" => "Photo media1",
  22. "media_type" => "image",
  23. "alt_text" => "alternate text"
  24. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement