Get the url of a file uploaded via XML RPC
-
Hello.
After many hours I was able to upload files via XML RPC, but is there a way to get as result the new URL of the file?
I have two codes. This one works fine but I get only “bool(true)” as result:
//code 1 $XmlRpc_result = null; $XmlRpc_client = new IXR_Client ($rpcurl); $fs = filesize ($filename); $file = fopen ($filename, 'rb'); $filebits = fread ($file, $fs); fclose ($file); $updata = array ( 'name' => $saveas, 'type' => $filetype, 'bits' => new IXR_Base64 ($filebits) ); $params = array(0,$username,$password,$updata); try{ $XmlRpc_result = $XmlRpc_client->query( 'metaWeblog.newMediaObject',$params ); var_dump ($XmlRpc_result); } catch (Exception $e){ var_dump ( $e->getMessage ()); } }
Before getting to that code, I was trying to upload files using this code:
//code 2 $request = xmlrpc_encode_request('metaWeblog.newMediaObject',$params); $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_URL, $rpcurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 1); $results = curl_exec($ch); curl_close($ch); echo $results;
Although this second code doesn’t upload files successfully (I get Warnings and it creates a 0 bytes file), it returns results, and among them the final destination of the uploaded file:
Warning: strlen() expects parameter 1 to be string, array given in [...]\xmlrpc.php on line 2809 (three more warnings) filenew-image.jpg urlhttps://..../wp-content/uploads/2011/02/new-image.jpg typeimage/jpeg 1
So what I’m looking for is, either make code 1 return the new URL of the file, or make code 2 work.
If anyone can help me out, please do! Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get the url of a file uploaded via XML RPC’ is closed to new replies.