I found a solution !
file_put_contents($filepath, base64_decode($data));
// Make sure the image exist
if (!file_exists($filepath)){return;}
// Load the image
$file = file_get_contents($filepath);
// Get the filename
$filename = $image_name? $image_name : basename($filepath);
// Initiate curl.
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_URL, $url .'/wp-json/wp/v2/media/' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $file );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Content-Disposition: form-data; filename=\"$filename\"",
'Authorization: Bearer ' .$result_auth->access_token,
] );
$result = curl_exec( $ch );
curl_close( $ch );
// Decode the response
$api_response = json_decode($result);
return $api_response;
Related Posts:
- How do I change/modify the_post_thumbnail(); html output?
- What’s the best way to use the Featured Image for responsive web design?
- How to add a class to the attachment images
- cURL 28 error after switch from to brew php 7.2 on localhost
- How do I hook into WordPress to save an uploaded photo as an alternate size to an existing photo?
- How to check if image is already stored in a site’s post database? (network)
- Adding a custom image upload size and making it selected by default?
- How do i post data to url with fields?
- Where Do Image Dimensions Get Added To A Filename?
- I have a background-image in css file but don’t show in site.how to fix this prblm. i sent screenshot. thx
- How do I stop an Image Address from loading in the Browser?
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- REST API custom endpoint to fetch pages and posts not working
- WooCommerce REST API AJAX Auth – 401 response
- Looping through and combining calls to Woocommerce REST API
- How to get the url of the entry in which an image belongs
- How to add a PHP scripts into WordPress
- get Woocommerce product format json for WP_Query
- Featured images duplicating and replacing next image
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Get list of posts from attachment
- I can’t load my images from a js file using wp_localize_script
- How to create an unordered list of images separate from the content
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Get the image title and alt from custom query
- How to include different html tags in the header for different pages?
- How to always display full size image
- what’s the syntax for if the image exists get the image?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Retrieving specific images from Media Library
- How do I routinely extract the thumbnail of the most recent post?
- How to change this internal image link parameter using PHP?
- add class to background image
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- Pass php to database in JQuery: With AJAX?
- How to resize an image server-side before upload?
- Creating image gallery in wordpress
- Retrieve first image url from custom post with pagination
- Image limit from 1 to 5
- Name Input from widget displays Sidebar name instead of saved data
- Gallery requires a featured image but does not show it in posts/pages
- Snapshot Theme from WooThemes — empty ‘alt’ attribute
- Changing 2011 theme header image based on user dropdown
- Setting post thumbnail sizes in template file and functions.php
- images in wordpress themes
- Determine if only one image attached to a post/page
- How to use custom fields to replace top-level parent title with an image using wp_list_pages?
- Crop images in both sides on wordpress [duplicate]
- upload images on front by user using form
- How do I return an image from a script
- PHP-Code inside Href-Tag
- HTML in PHP problem [closed]
- Adding slides to an existing carousel manually
- Where to store the images of a custom WordPress theme?
- Display Post Titles on top of the_post_thumbnail()
- add if statement to the featured image
- An automatic way to crop images of different sizes
- How to remove the intro animation which appears during the load up of some WordPress themes? [closed]
- How to automatically convert images to WebP on WordPress?
- Remove default Image Sizes
- Headers already sent error with get_template_part in REST API call
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Understanding responsive imagery
- How to pass and validate nonce in custom REST routes
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- WooCommerce: write featured image dimensions to custom fields in product’
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Generate and upload screenshot as featured image for user-submitted post
- bloginfo url in javascript
- Use URL query string in img src attribute
- REST API custom endpoints for metaboxes
- Add/alter image attribute before render
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- How Create Automatically Image jpg.webp from image .jpg without delete or change original images upload
- Adding Microsoft Teams Incoming Webhook to WordPress, Problem with Rest Route?
- WordPress REST API – Custom field not added to pages
- Using Featured Image as Hero Background in Word Press
- How can add alt tag in following code. Image are showing dynamic in wordpress
- Adding caption to all images inside an article
- What is different about using admin-ajax.php in an endpoint and just submitting a form from the front end?
- REST API Plugin Update call back not updating the plugin
- regsiter a new user through WordPress API with Google SSO doesn’t work properly
- Application password header not checked in REST API
- How to add a shortcode for an image in the following function
- register_rest_route, Compare purchase codes and send a response
- Can external API content be added to Rest API in WordPress
- Authorization and execution of the link
- HELP PLEASE PHP slider css
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- Registered a REST Route but I’m Getting a 400 Bad Request
- Image alt tag is showing post title instead of Alt Text
- WP_Error Object in wp_remote_post & wp_remote_get
- WP rest api and litespeed incompatibility
- Responsive images, per image type?
- Custom rest fields not loaded in rest api cpt response
- REST API request between domain and subdomain