View upload-base64-image-to-wp.php
<?php | |
function tidaweb_upload_base64_image( $base64_image_data, $base64_file_name ) | |
{ | |
// check and get path of upload directory | |
$upload_dir = wp_upload_dir(); | |
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR; | |
$img = $base64_image_data; | |
if(strpos($img, 'image/jpg') !== false) | |
{ |
View convert-wp-image-to-base64.php
<?php | |
function tidaweb_image_url_to_base64( $attach_id ) | |
{ | |
// get image src -> $image_info[0] | |
$image_info = wp_get_attachment_image_src( $attach_id, 'full' ); | |
$image_file = file_get_contents( $image_info[0] ); | |
// get filename from url | |
$filename = basename( get_attached_file( $attach_id ) ); | |
$image_file_type = wp_check_filetype( $filename ); |