Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Upload photo to site.
*
* @author Scott Anderson <scott.anderson@webdevstudios.com>
* @since NEXT
* @param Request $request Request form date to format for api.
* @return int Id of image uploaded.
*/
public function upload_photo( Request $request ) : int {
$this->new_construct();
$file = file_get_contents( $request->file( 'featured_image_upload' ) );
$response = json_decode( $this->client->post( "{$this->site_url}/wp-json/wp/v2/media", [ 'headers' => $this->image_header( $request ), 'body' => $file ] )->getBody() );
return $response->id;
}
/**
* Specialized image header.
*
* @author Scott Anderson <scott.anderson@webdevstudios.com>
* @since NEXT
* @param Request $request Request form date to format for api.
* @return array
*/
private function image_header( Request $request ) : array {
return array_merge( $this->headers, [
'Content-Disposition' => 'attachment; filename=testing.jpeg',
'Content-Type' => 'image/png',
]);
}
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.