使用JSON REST API将媒体上传到WordPress网站时遇到麻烦。
使用以下代码,我可以上传照片,但是没有为他们分配任何信息,甚至没有为名称分配信息-实际上,名称自动成为URL和文件名(不带扩展名)。
$username = "ZX";
$password = "ZX";
$host = 'http://ZX.com/wp-json/wp/v2/media';
$data = json_encode($data);
$file = '/Users/xx.png';
$imagedata = file_get_contents($file);
$process = curl_init($host);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_TIMEOUT, 50);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type:image/png','Content-Disposition:attachment;filename='.$file));
$return = curl_exec($process);
print_r($return);
我将如何向上传内容分配以下数据?
$data = array(
"status" => "draft",
"title" => "Photo media",
"description" => "Photo media1",
"media_type" => "image",
"alt_text" => "alternate text"
);