In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to transfer php blob to base64". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The method of converting php blob to base64: 1. Open the corresponding code file; 2. Modify the content of PHP to "fetch (" / path/to/server ", {method:" POST "body: files [I]})." That's it.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
How to transfer php blob to Base64?
Convert local image Blob to base64 in PHP
Specific problem description:
I am writing (HTML) forms for internal tools. Users can fill in the data about the problem and attach screenshots. The form is then submitted to PHPMailer via Ajax to be sent. The problem lies in the screenshot. Due to system limitations, I can't get users to actually upload files to the server.
Currently, I am using the HTML5 file reader to select files. Then, I convert the image Blob to base64 and send it to PHPMailer to convert it to attachment. This actually works very well. However, I have a file size problem. Specifically, it is the test image of 1000px x 1000px (402KB). The resulting base64 string is more than a million characters and the request returns 413 (the request entity is too large).
I know that base64 is not an effective way to transfer large images, and I have seen various articles about retrieving / converting image speckles from a database. What I can't find is information about retrieving the local image Blob and converting it to base64.
My picture Blob URL is as follows: blob: http://example.com/18960927-e220-4417-93a4-edb608e5b8b3
Is it possible to get this local image data in PHP and convert it to base64?
I can't release much source code, but the following will give you an idea of how I use FileReader
_ window.onload=function () {window.URL = window.URL | | window.webkitURL;var fileSelect = document.getElementById ("fileSelect"), fileElem = document.getElementById ("fileElem"), fileList = document.getElementById ("fileList"); fileSelect.addEventListener ("click", function (e) {if (fileElem) {fileElem.click ();} e.preventDefault (); / / prevent navigation to "#"}, false) } function handleFiles (files) {if (! files.length) {fileList [XSS _ clean] = "
No files selected!
";} else {fileList [XSS _ clean] ="; var list = document.createElement ("ul"); fileList.appendChild (list); for (var I = 0; I
< files.length; i++) { if(files[i].size >1000000) {alert (Files [I] .name +'is too big. Please resize it and try again.');} else {var li = document.createElement ("li"); list.appendChild (li); var img = document.createElement ("img"); img.src = window.URL.createObjectURL (Files [I]); img.height = 60; img.setAttribute ("class", "shotzPrev"); img.onload = function () {window.URL.revokeObjectURL (this.src) } li.appendChild (img); var info = document.createElement ("span"); in [XSS _ clean] = Files [I] .name + "
"+ files [I] .size +" bytes "; li.appendChild (info);}
Solution:
You can set the POST php of the File object
Fetch ("/ path/to/server", {method: "POST" body: files [I]}) .then (response = > console.log (response.ok)) .catch (err = > console.error (err)); that's all for php blob to base64. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.