Posted March 26Mar 26 comment_274 Tròm thấy ae trong forum đang kiếm nơi lưu trữ ảnh xiếc an toàn mà không "bị đá". Mình đi dạo một vòng thì thấy ae xài từ imgur đến google photos, đa số là ae đều bị đá. Nên mình lập topic này để gợi ý cho ae một cách up ảnh khác, đúng với tiêu đề luôn, đó là chúng ta sử dụng mã hóa base64.Thôi, không lòng vòng tam quốc nữa, sau đây là code.<div class="mainblok"> <div class="phdr">Tải lên hình ảnh Mã hóa Base64</div> <div class="list4" style="text-align:center"><input id="imageInput" type="file" onchange="encode();" /></div> <div class="list4" style="text-align:center" id="display"></div> <div class="list4" style="text-align:center"><textarea id="textoutput" style="width:92%" rows="8"></textarea></div> <script> function encode() { var selectedfile = document.getElementById("imageInput").files; if (selectedfile.length > 0) { var imageFile = selectedfile[0]; var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent) { var srcData = fileLoadedEvent.target.result; var newImage = document.createElement('img'); newImage.src = srcData; document.getElementById("display").innerHTML = newImage.outerHTML; document.getElementById("textoutput").value = fileLoadedEvent.target.result; } fileReader.readAsDataURL(imageFile); } } </script> </div>
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.