I'am developing a plugin that will push files to a remote server via http upload. Currently I got it to work with CURL doing something like this:

$post = array("post_file"=>"@/path/FILE.EXT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

Now my question is how I can achieve the same using wp_remote_host. How is the file included in the 'body' argument.

For more info see this. http://codex.wordpress.org/Function_API/wp_remote_post


Something like this, perhaps.

$args['body'] = array('post_file'=>'@/path/FILE.EXT');
wp_remote_post($url, $args);

The $args array contains the parameters for the post. The body parameter controls what is posted. There's many other possible parameters as well. See http://codex.wordpress.org/HTTP_API#Other_Arguments

Note that the @file method may be specific to curl, and might not work with the other possible HTTP transports that WP supports.

| improve this answer | |

I read through the source code in wp-includes/class-http.php and wp_remote_post() doesn't support sending files. I think you'd need to re-write the WP_Http class to make this work or otherwise write a plugin or extension to handle this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.