PHP base64解码函数无法解码base64图像字符串

php base64 decode function is unable to decode base64 image string

本文关键字:base64 解码 图像 字符串 函数 PHP      更新时间:2023-09-26

since ie7 &默认情况下,ie8无法解码base64图像字符串,我正在寻找另一种方法来实现它。在谷歌上搜索了这个问题后,我在http://dean.edwards.name/weblog/2005/06/base64-ie/上找到了一个很好的教程。

据我所知,解码过程由两个短脚本组成,如下所示:

按作者指示命名为base64.php

<?php
$data = split(";", $_SERVER["QUERY_STRING"]);
$type = $data[0];
$data = split(",", $data[1]);
header("Content-type: ".$type);
echo base64_decode($data[1]);
?>

B。javascript

,插入到嵌入base64图像字符串的页面头部标签内,最后将图像字符串传递给base64.php进行处理&解码。

<script type="text/javascript">
// a regular expression to test for Base64 data
var BASE64_DATA = /^data:.*;base64/i;
// path to the PHP module that will decode the encoded data
var base64Path = "base64.php";
function fixBase64(img) {
  // check the image source
  if (BASE64_DATA.png(img.src)) {
    // pass the data to the PHP routine
    img.src = base64Path + "?" + img.src.slice(5);
  }
};
// fix images on page load
onload = function() {
  for (var i = 0; i < document.images.length; i++) {
    fixBase64(document.images[i]);
  }
};
</script>

不幸的是,php base64解码函数无法解码图像字符串为ie7 &在我的例子中是ie8

我的文档类型是DTD XHTML 1.0 Transitional &charset=utf-8

你知道这里出了什么问题吗?

演示链接:

base64-string-without-php-decoder: http://silentpond.eu5.org/base64-string-without-php-decoder.php

base64-string-with-php-decoder: http://silentpond.eu5.org/base64-string-with-php-decoder.php

谢谢,

在IE中,至少在版本8或更早的时候。url的最大长度约为2047字节。更多信息请访问:http://support.microsoft.com/kb/208427