由于ie7
&ie8
默认情况下无法解码 base64 图像字符串,我一直在寻找一种替代方法。在谷歌搜索该问题后,我在http://dean.edwards.name/weblog/2005/06/base64-ie/找到了一个很好的教程。
据我了解,解码过程由两个简短的脚本组成,如下所示:
A.php base64解码函数
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图像字符串的页面的head标签中,最后应该将图像字符串传递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 decode 函数无法将图像字符串解码为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
谢谢,