Answer the question
In order to leave comments, you need to log in
How to get image base64 code?
how to get image base64 code? I need the image code. How to get it using php javascript or other methods?
Answer the question
In order to leave comments, you need to log in
function imgToBase64(file, callback) {
var fr = new FileReader();
fr.onload = callback;
fr.readAsDataURL(file);
}
<input type="file" onChange="imgToBase64(this.files[0], fn)" />
In php (not my solution)
<?php
$image = 'img/phone.png';
$imageData = base64_encode(file_get_contents($image));
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;
echo "<img src=\"$src\" alt=\"\" />";
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question