M
M
Max Shteklya2016-09-22 22:05:43
PHP
Max Shteklya, 2016-09-22 22:05:43

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

3 answer(s)
D
Deodatuss, 2016-09-22
@Deodatuss

tyts

M
Medin K, 2016-09-22
@medin84

function imgToBase64(file, callback) {
    var fr = new FileReader();
    fr.onload = callback;
    fr.readAsDataURL(file);
}

<input type="file" onChange="imgToBase64(this.files[0], fn)" />

https://jsfiddle.net/5bca19vz/1/
https://jsfiddle.net/o8b6162j/1/
something like this

A
A person from Kazakhstan, 2016-09-23
@LenovoId

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 question

Ask a Question

731 491 924 answers to any question