English 中文(简体)
通过轮椅张贴图像 文件XML RPC
原标题:Posting images via wp.uploadFile XML RPC

我想通过XML RPC向我的言词博客传播图像,然后通过信标将图像放在文字上。

但是,我的话语气和头盔。 档案不能归还数据库64 ,而没有有效形象。

这里是我的营地法典。

<?php $q = new IXR_Client( http://myblog.com/xmlrpc.php );
$mediaarray = array(
"name" => $image_name,
"type" => $atrybuty[mime],
"bits" => base64_encode($file),
"overwrite" => false,
);
if(!$q->query( wp.uploadFile , 1, $uzyt, $has, $mediaarray)){

    echo $q->getErrorCode(). :  .$q->getErrorMessage();
}

var_dump($q->getResponse());

反应

array(3) { ["file"]=> string(24) "Pein_by_azurewrath87.jpg" 

[“url”]=> string(84)“http://myblog.com/wp-content/uploads/2007/01/Pein_by_azurewrath87.jpg” [“类型”]=> string(10) “image/jpeg” }

But image is base64_encodet. How to proper send image to wordpress via wp.uploadFile or metaWeblog.newPost method.

最佳回答

你们必须使用IXR_Base64(数据)将数据转换为实际数据标,而不仅仅是一个包含基64内容的图象。

<?php $q = new IXR_Client( http://myblog.com/xmlrpc.php );
$mediaarray = array(
"name" => $image_name,
"type" => $atrybuty[mime],
"bits" => new IXR_Base64($file),
"overwrite" => false,
);
问题回答

I encountered exactly the same issue, here the snippet I use to manage post attachments while synchronizing posts accrosss different instances of wordpress.

If want you to test this snippet, just set $post_to_sync->post_id with a post ID which has attachments :

    /****************************BEGIN ATTACHMENTS****************************/
//get attachments from the original content
$attachments = & get_children( array(
         post_parent  => $post_to_sync->post_id, //replace here with a post id
         post_type    =>  attachment ,
));
if ( $attachments != array() ) {
    foreach ( $attachments as $attachment_id => $attachment ) {
        $params = array(
                0,
                XMLRPC_USER,
                XMLRPC_PWD,
                array(
                         name  => basename( get_attached_file( $attachment_id ) ), //$attachment->post_title,
                         type  => $attachment->post_mime_type,
                         bits  => new IXR_Base64 ( file_get_contents ( get_attached_file( $attachment_id ) ) ),
                         post_parent  => $id_int,
                )
        );
        $client->query( metaWeblog.newMediaObject ,$params) ;
        echo  <br> <br>  ;
        var_dump($client->getResponse());
        echo  <br> <br>  ;echo  <br> <br>  ;echo  <br> <br>  ;
    }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签