WordPress通过XMLRPC上传图像和媒体

时间:2016-07-25 18:29:00

标签: php wordpress image media xml-rpc

我想通过XML-RPC将一些媒体和图像上传到我的WordPress网站 我用这个代码来实现这个目的:

$filename = 'sample.jpg';
$mime = 'images/jpeg';
$data = file_get_contents($filename);
var_dump($wpClient->uploadFile($filename, $mime, $data, false));

文件上传到媒体,我得到了这个输出:

array(13) {
  ["attachment_id"]=>
  string(4) "7430"
  ["date_created_gmt"]=>
  object(stdClass)#3 (3) {
    ["scalar"]=>
    string(17) "20160727T19:57:29"
    ["xmlrpc_type"]=>
    string(8) "datetime"
    ["timestamp"]=>
    int(1469649449)
  }
  ["parent"]=>
  int(0)
  ["link"]=>
  string(56) "http://url.com/wp-content/uploads/2016/07/sample.jpg"
  ["title"]=>
  string(10) "sample.jpg"
  ["caption"]=>
  string(0) ""
  ["description"]=>
  string(0) ""
  ["metadata"]=>
  string(0) ""
  ["type"]=>
  string(11) "images/jpeg"
  ["thumbnail"]=>
  string(56) "http://url.com/wp-content/uploads/2016/07/sample.jpg"
  ["id"]=>
  string(4) "7430"
  ["file"]=>
  string(10) "sample.jpg"
  ["url"]=>
  string(56) "http://url.com/wp-content/uploads/2016/07/sample.jpg"
}

但上传的文件没有任何标题或说明,我该如何提交?

1 个答案:

答案 0 :(得分:1)

我找到了自己的方式, 上传文件后,我们应该编辑帖子并修改那些元素

相关问题