#25290 closed defect (bug) (duplicate)
seems can't attach the uploaded photo to the created post
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6.1 |
Component: | XML-RPC | Keywords: | XML-RPC attachment |
Focuses: | Cc: |
Description (last modified by )
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?
Change History (3)
Note: See
TracTickets for help on using
tickets.
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).