Ready to get started?Download WordPress


[resolved] Image upload via form on php script (3 posts)

  1. Whithil XBR
    Posted 2 years ago #

    I'm using a simple XMLRPC form to create new posts for a real estate website, so people from there would be able to quickly and easily add new posts.
    Everything went ok, even the custom fields, now I just need a way to send images to the wordpress media library and get the link from the uploaded image in a custom field. But I couldn't figure out this part.
    Is there a way to do it?

    Any help will be appreciated.

  2. praeix
    Posted 2 years ago #

    Maybe this post will help? It uses the Settings API (which everybody should be using anyway).

    Multiple Upload Inputs In A WordPress Theme Options Page

  3. Whithil XBR
    Posted 2 years ago #

    Thanks but I already found this code, and it worked fine to upload the images:

    $blogid=1; //Post ID
    $filetype = "image/jpeg";
    $filename = "remote_filename.jpg";
    xmlrpc_set_type($file,'base64'); // <-- required!
    $params = array($blogid,$username,$password,
    $request = xmlrpc_encode_request('wp.uploadFile',$params);
    $result = go($request,$rpcurl);
    function go($request,$rpcurl){
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_POSTFIELDS,$request );
        $result = curl_exec($ch);

    now I just need to get the url from the uploaded file in wordpress' "media-library".

Topic Closed

This topic has been closed to new replies.

About this Topic