由于 ie7
和 ie8
默认情况下无法解码 base64 图像字符串,因此我一直在寻找替代方法。在谷歌搜索这个问题后,我在 http://dean.edwards.name/weblog/2005/06/base64-ie/ 找到了一个很好的教程。 .
据我所知,解码过程由两个简短的脚本组成,如下所示:
一个。 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
插入到页面的head标签中,嵌入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-解码器:http://silentpond.eu5.org/base64-string-with-php-decoder.php
谢谢,
最佳答案
在 IE 中,至少是版本 8 和更早版本。 url 的最大长度约为 2047 字节。可以在此处找到更多信息:http://support.microsoft.com/kb/208427
关于php base64解码函数无法解码base64图像字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15667258/