Support » Plugin: iOS images fixer » XML-RPC Upload Feature Request

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Bishoy.A

    (@bishoya)

    Hi,

    Could you share your XML-RPC upload code?

    Bishoy

    #!/usr/bin/php
    <?php
    
      if ( empty($argv[1]) ){
        exit;
      }
    
      $rpcurl='https://www.foo.com/xmlrpc.php';
      $username='bar';
      $password='rootme';
      $blogid=1; //Post ID
    
      $file=file_get_contents("$argv[1]") or die();
      $filename = basename($argv[1]);
    
      $path_parts = pathinfo("$filename");
      $filetype=$path_parts['extension'];
    
      if ( strcasecmp ( $filetype , "mp4" ) == 0 ){
        $filetype = "video/mp4";
      } else {
        $filetype = "image/jpeg";
      }
    
      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_HTTPHEADER, array('Expect:')); //Fixes the HTTP/1.1 417 Expectation Failed Bug
          curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
        //  curl_setopt($ch,CURLOPT_VERBOSE,1);
          $result = curl_exec($ch);
      }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘XML-RPC Upload Feature Request’ is closed to new replies.