I need to encode jpeg images on a webserver using base64_encode so I can put them into an XML data file for use on another system... I am reasonably new to base64 and am trying to encode an image using base64_encode() and output the results in a browser to ensure it has encoded it correctly, which it looks like it has. Then I am trying to decode it and display the image in a browser it insure that the encoded image was actually encoded properly but I cannot seem to get it to output the image to a browser window. Below is the basic code that I am using to try and achieve this... Please help!
<?
//get the base64 encoded image
$tempfile = "/path_to_the_image_on_webserver/image1.jpg";
$handle = fopen($tempfile,'rb');
$file_content = fread($handle,filesize($tempfile));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
//then echo to browser which I thought should have worked to display the image as:
echo '<img src="data:image/jpeg;base64,'.$encoded.' ">';
//then I tried the below but neither option worked.
$decoded = base64_decode($encoded);
echo '<img src="'.$decoded.'">';
?>