[wp-trac] [WordPress Trac] #25290: seems can't attach the uploaded photo to the created post

WordPress Trac noreply at wordpress.org
Thu Sep 12 07:10:44 UTC 2013


#25290: seems can't attach the uploaded photo to the created post
--------------------------------+------------------------------
 Reporter:  zuola               |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  XML-RPC             |     Version:  3.6.1
 Severity:  normal              |  Resolution:
 Keywords:  XML-RPC,attachment  |
--------------------------------+------------------------------

Old description:

> I can not attach the uploaded photo to the specific post when I using
> XML-RPC, I found solutions from stackoverflow.com :
> http://stackoverflow.com/questions/7607473/how-to-create-new-post-with-
> photo-attached-in-wordpress-using-xmlrpc
>
> solution below:
> I am using :
>
> {{{
>         DEFINE('WP_XMLRPC_URL', 'http://example.org/xmlrpc.php');
>                 DEFINE('WP_USERNAME', 'zola');
>                 DEFINE('WP_PASSWORD',
> 'fuckchinagovernmentandnotrealypsw');
>
>                 require(dirname(__FILE__) . '/wp-load.php' );
>                 require(ABSPATH . WPINC . '/class-IXR.php');
>                 $upfile=$_FILES['file'];
>                 $fs = filesize($_FILES['file']['tmp_name']);
>                         $file = fopen($_FILES['file']['tmp_name'], 'rb');
>                         $filedata = fread($file, $fs);
>                         fclose($file);
>                 $data = array(
>                                 'name'  => $_FILES['file']['name'],
>                                 'type'  => strtolower($upfile['type']  ),
>                                 'post'  => $postID, //specific post we
> want attach to
>                                 'bits'  => new IXR_Base64($filedata),
>                                 false // overwrite
>                                                  );
>
>                         $status = $rpc->query(
>                                 'metaWeblog.newMediaObject',
>                                 $postID,
>                                 WP_USERNAME,
>                                 WP_PASSWORD,
>                                 $data
>                                                          );
>
>                                 $uploaded_images__url
> =$rpc->getResponse();
>
> }}}
> Wordpress team  need add
>
> {{{
> post = $data['post'];
> }}}
> before
>
> {{{
> $name = sanitize_file_name( $data['name'] );
>  $type = $data['type'];
>  $bits = $data['bits'];
> }}}
> in class-wp-xmlrpc-server.php near 4925 line.
>
> then we can be attach to whatever post we desire!
>
> can anyone fix that issue?

New description:

 I can not attach the uploaded photo to the specific post when I using XML-
 RPC, I found solutions from stackoverflow.com :
 http://stackoverflow.com/questions/7607473/how-to-create-new-post-with-
 photo-attached-in-wordpress-using-xmlrpc

 solution below:
 I am using :

 {{{
         DEFINE('WP_XMLRPC_URL', 'http://example.org/xmlrpc.php');
                 DEFINE('WP_USERNAME', 'zola');
                 DEFINE('WP_PASSWORD', 'notrealypsw');

                 require(dirname(__FILE__) . '/wp-load.php' );
                 require(ABSPATH . WPINC . '/class-IXR.php');
                 $upfile=$_FILES['file'];
                 $fs = filesize($_FILES['file']['tmp_name']);
                         $file = fopen($_FILES['file']['tmp_name'], 'rb');
                         $filedata = fread($file, $fs);
                         fclose($file);
                 $data = array(
                                 'name'  => $_FILES['file']['name'],
                                 'type'  => strtolower($upfile['type']  ),
                                 'post'  => $postID, //specific post we
 want attach to
                                 'bits'  => new IXR_Base64($filedata),
                                 false // overwrite
                                                  );

                         $status = $rpc->query(
                                 'metaWeblog.newMediaObject',
                                 $postID,
                                 WP_USERNAME,
                                 WP_PASSWORD,
                                 $data
                                                          );

                                 $uploaded_images__url
 =$rpc->getResponse();

 }}}
 Wordpress team  need add

 {{{
 post = $data['post'];
 }}}
 before

 {{{
 $name = sanitize_file_name( $data['name'] );
  $type = $data['type'];
  $bits = $data['bits'];
 }}}
 in class-wp-xmlrpc-server.php near 4925 line.

 then we can be attach to whatever post we desire!

 can anyone fix that issue?

--

Comment (by dd32):

 I'm fairly certain we support this already.

 If the 'post_id' field is present in the $data array, it'll be used (where
 as you're using the 'post' field).

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25290#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list