我正在尝试将我的本地图片上传到我在wordpress.com上的博客,我试试这段代码
$request = curl_init('https://public-api.wordpress.com/rest/v1/sites/mywordpressbloganonym.wordpress.com/media/new');
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'media' => '@C:/Users/aditia/myimage.jpg',
'media[0]' => '@C:/Users/aditia/myimage.jpg',
'media[]' => '@C:/Users/aditia/myimage.jpg'
));
curl_setopt($request, CURLOPT_HTTPHEADER, array(
"Content-Type: multipart/form-data",
"Authorization: BEARER mybrearertokenrfromauth"
));
// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
echo curl_exec($request);
// close the session
curl_close($request);
我总是得到
{"media":[],"errors":[{"error":"upload_error","message":"File is empty. Please upload something more substantial."},{"error":"upload_error","message":"File is empty. Please upload something more substantial."}]}
我正在使用https://developer.wordpress.com/docs/api/1.1/post/sites/ $ site / media / new / 但直接从控制台使用curl工作,请帮助我的代码中缺少什么?