I have written a Javascript which can preview the Imgae in a IMG tag. Now I want the data uri format of this image so that I can display it using mPDF.
The following is the IMG ID tag in php file
<div class="logo_prev">
<img id="img_prev" alt="Your logo" class="img-thumbnail invoice-logo img-responsive"/>
</div>
<br>
<input type='file' onchange="logoImg(this);" name="invoice_logo" class="select-logo" data-validation="mime size" data-validation-allowing="jpg, png, gif" data-validation-max-size="2M" data-validation-error-msg="Only jpg, gif or png are allowed (Max 2mb)" />
The Javascript code is
function logoImg(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#img_prev')
.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
and I have written the code like the following:
$image = $_POST['img_prev'];
$imageData = base64_encode(file_get_contents($image));
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;
Now I want to access this $src
variable in the PHP file. But it shows me nothing in that variable.