Skip to content

Instantly share code, notes, and snippets.

@kloon

kloon/file.php Secret

Created July 30, 2014 08:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kloon/acc9be756b8352297b5b to your computer and use it in GitHub Desktop.
Save kloon/acc9be756b8352297b5b to your computer and use it in GitHub Desktop.
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