wp_remote_post wp_remote_request file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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