Base64 encoded image is stored in table but when i m trying to display its not showing in edit page. Below is the code of controller and blade file.
$base64Image = null;
if ($request->hasFile('profile_picture')) {
$image = $request->file('profile_picture');
$base64Image = base64_encode(file_get_contents($image));
}
$teacher->profile_picture = $base64Image;```
<div class="form-group">
<label>Upload Profile Picture</label>
<input type="file" class="dropify" name="profile_picture" id="dropify-event" data-default-file="data:image/jpeg;base64,{{ $teacher->profile_image }}">
<img src="data:image/png;base64,{{ base64_encode($teacher->profile_image) }}" alt="Profile Picture">
</div>
2
Answers
You can try this code to decode any base64 file like image, pdf, mp3, etc. without knowing and having actual file details inside base64 encoded string.
add below function to the same class or use trait for identifying file format, you can also add more mime types to this array if you are dealing with any other file formats as well.
by using above method you can store base64 image string into database.
and you can display this as usual we do in laravel inside src attr of image tag.
It seems that you have issues in your controller and view. Add image source as variable to your controller and change the way you are showing base64 encoded image in your view as below: