簡體   English   中英

php base64解碼功能無法解碼base64圖像字符串

[英]php base64 decode function is unable to decode base64 image string

由於ie7ie8默認情況下無法解碼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解碼功能無法將圖像字符串解碼為ie7ie8

我的文檔類型是DTD XHTML 1.0 Transitionalcharset=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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM