P粉0051346852023-08-24 14:48:24
您也可以直接從 XMLHttpRequest 取得 BLOB 物件。將responseType 設定為blob 就可以了。這是我的程式碼:
var xhr = new XMLHttpRequest(); xhr.open("GET", "http://localhost/image.jpg"); xhr.responseType = "blob"; xhr.onload = response; xhr.send();
回應函數如下所示:
function response(e) { var urlCreator = window.URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL(this.response); document.querySelector("#image").src = imageUrl; }
我們只需在 HTML 中建立一個空白圖像元素即可:
<img id="image"/>
P粉7425503772023-08-24 00:00:37
問題是我有十六進位數據,需要在進行 Base64 編碼之前轉換為二進位。
在 PHP 中:
base64_encode(pack("H*", $subvalue))