I want upload image using api on my page so any tell me how i do it?
Now i work with this api
but it's doesn't help me for upload image on page or post.
I use wordpress json api plugin.
I want upload image using api on my page so any tell me how i do it?
Now i work with this api
but it's doesn't help me for upload image on page or post.
I use wordpress json api plugin.
You can do using following code. Here I have use wp_handle_upload
.
$param = array('search' => 'XXXXXXXX');
$imagetype = array(
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff'
);
$override = array(
'mimes' => $imagetype,
'test_form' => false
);
$upload_file = wp_handle_upload( $_FILES['YOUR_UPLOAD_FILE_NAME'], $override );
remove_filter( 'upload_dir', array($this, 'change_upload_dir') );
if ( isset( $upload['error'] ) ){
// DO ACTION ACCORDINGLY
} else {
// File is uploaded successfully.
$uploaded_file_url = $upload_file['url'];
$uploaded_file_name = basename($upload_file['url']);
}