WordPress: Posting images using XML-RPC
The following code uploads a file using xmlrpc... and without using all kinds of libs, you just need the regular php-xmlrpc module.
© GeekLabInfo
$rpcurl='http://www.geeklab.info/xmlrpc.php'; $username='admin'; $password='your-password'; $blogid=1; //Post ID $file=file_get_contents('file.jpg'); $filetype = "image/jpeg"; $filename = "remote_filename.jpg"; xmlrpc_set_type($file,'base64'); // <-- required! $params = array($blogid,$username,$password, array('name'=>$filename,'type'=>$filetype,'bits'=>$file,'overwrite'=>false)); $request = xmlrpc_encode_request('wp.uploadFile',$params); $result = go($request,$rpcurl); print_r($result); function go($request,$rpcurl){ $ch = curl_init(); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_URL,$rpcurl); curl_setopt($ch,CURLOPT_POSTFIELDS,$request ); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); }

