Using XML-RPC to upload images
-
Hi
I am using the xml-rpc interface and trying to use it to upload an image to my blog.
I use the following code:
$username = "username"; $password = "password"; $rpcurl = "http://myblog.com/xmlrpc.php"; $image = fopen("file.jpg","r"); $file = fread($image,filesize("file.jpg")); fclose($image); $filetype = "image/jpeg"; $filename = "testimage.jpg"; $result = wpUploadFileXMLRPC($blogid,$rpcurl,$username,$password,$filename, $filetype, $file); echo(print_r($result)); function wpUploadFileXMLRPC($blogid,$rpcurl,$username,$password,$filename, $filetype, $file){ $params = array('',$username,$password,array('name'=>$filename, 'type'=>$filetype,'bits'=>$file,'overwrite'=>true)); $request = xmlrpc_encode_request('wp.uploadFile',$params); $result = makeCall($request,$rpcurl); return($result); }
I get the following response from the blog:
<?xml version=”1.0″?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member><name>file</name><value><string>wpid-testimage.jpg</string></value></member>
<member><name>url</name><value><string>http://myblog.com/wp-content/uploads/2010/03/wpid-testimage8.jpg</string></value></member>
<member><name>type</name><value><string>image/jpeg</string></value></member>
</struct>
</value>
</param>
</params>
</methodResponse>Yet when I go to the URL given.. all that I see is the path of the URL not an image.
Can anyone see what’s going wrong?
Thanks
- The topic ‘Using XML-RPC to upload images’ is closed to new replies.