WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#25290 closed defect (bug) (duplicate)

seems can't attach the uploaded photo to the created post

Reported by: zuola Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6.1
Component: XML-RPC Keywords: XML-RPC attachment
Focuses: Cc:

Description (last modified by dd32)

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)

#1 @dd32
7 years ago

  • Description modified (diff)

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).

#2 follow-up: @dd32
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See [21896] / #13917 which was fixed in 3.5

#3 in reply to: ↑ 2 @zuola
7 years ago

  • Keywords changed from XML-RPC,attachment to XML-RPC attachment

Thanks dd32, I am double check and confirm you are right.

I can post and attach attachment to specific post without hack now.

Note: See TracTickets for help on using tickets.