0

I'm trying to retrieve image from server using the following code, but it isn't working:

<?php
    $result=file_get_contents("http://192.168.43.89/phpmyadmin/uploads/8.jpg");   
    header("content-type:image/jpeg");
    echo '<img src="' .base64_decode($result). '">';
?>

1 Answer 1

2

You firstly need to encode the image data you fetch to base64 using base64_encode(), then you must include the data properly inside your src-attribute (syntax: data:[<mediatype>][;base64],<data>), like this:

<?php
    $result=base64_encode(file_get_contents("http://192.168.43.89/phpmyadmin/uploads/8.jpg"));   
    //header("content-type:image/jpeg"); --> you don't need this if you are outputting HTML, only if you are outputting the image directly
    echo "<img src=\"data:image/jpeg;base64,$result\">";
?>

source: http://www.websiteoptimization.com/speed/tweak/inline-images/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.