Skip to content

Instantly share code, notes, and snippets.

@kloon

kloon/file.php Secret

Created Jul 30, 2014
Embed
What would you like to do?
wp_remote_post wp_remote_request file upload
<?php
// wp_remote_request way
$file = @fopen( 'path/to/file.txt', 'r' );
$file_size = filesize( 'path/to/file.txt' );
$file_data = fread( $file, $file_size );
$args = array(
'method' => 'POST'
'headers' => array(
'accept' => 'application/json', // The API returns JSON
'content-type' => 'application/binary', // Set content type to binary
),
'body' => $file_data
);
$result = wp_remote_request( 'https://domain.com/api/v2/uploads.json?filename=myfile.dat' $args );
// wp_remote_post way
$file = @fopen( 'path/to/file.txt', 'r' );
$file_size = filesize( 'path/to/file.txt' );
$file_data = fread( $file, $file_size );
$args = array(
'headers' => array(
'accept' => 'application/json', // The API returns JSON
'content-type' => 'application/binary', // Set content type to binary
),
'body' => $file_data
);
$result = wp_remote_post( 'https://domain.com/api/v2/uploads.json?filename=myfile.dat' $args );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.