imap体的Base64编码不起作用

时间:2017-07-30 13:22:54

标签: php encoding base64 imap

过去几天我到处都看了,但仍然无法找到答案。我有一个imap php应用程序,从我的Outlook帐户获取电子邮件,所有工作完美,消息显示不错但我有几个电子邮件的问题,体型返回base64但它没有正确编码(只有一对,所有其他base64得到很好的解码)。但解码前的这个是......

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/wAALCAB4AHgBAREA/8QAHwAAAQUBAQEB AQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1Fh ByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZ WmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEBAAA/APZqKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK/9k=

并解码后,它更加喋喋不休,而不是任何有意义的文字。这是什么以及如何正确解码?看看在线解码器,并说它无效

  

下面是电子邮件在outlook中的外观图像

enter image description here

1 个答案:

答案 0 :(得分:0)

  

演示:: http://phpfiddle.org/main/code/876m-khae

     

参考:http://php.net/manual/en/function.imagecreatefromstring.php

     

在此处查看在线工具解码:https://www.base64decode.org/

<?php

$base64_string ="/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/wAALCAB4AHgBAREA/8QAHwAAAQUBAQEB AQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1Fh ByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZ WmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEBAAA/APZqKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK/9k=
";

$decode_data = base64_decode($base64_string);

$image_create = imagecreatefromstring($decode_data);
if ($image_create !== false) {
    header('Content-Type: image/png');
    imagepng($image_create);
    imagedestroy($image_create);
}
else {
    echo 'An error occurred.';
}
?> 
  

注意::您还可以使用base64ToImage功能对此进行解码

示例:

<?php

function base64ToImage($base64_string, $output_file) {

     $file = fopen($output_file, "wb");

     $data = explode(',', $base64_string);

     fwrite($file, base64_decode($data[1]));
     fclose($file);

     return $output_file;
}


?>