This article describes how to use FileReader to encode a file into Base64 and upload it via AJAX, including the PHP code that the backend decodes and stores the file data, for more information about how to use AJAX, you cannot directly upload files. Generally, you can create a new iframe to complete the form submission process in it to achieve asynchronous file upload.
This can achieve better browser compatibility, but the amount of code will be relatively large, even if the file upload plug-in is used, such as plupload.
How can we achieve flexibility? just treat a file as a common form parameter like submitting form data through AJAX.
With a flash of light, it's okay to use the javascript FileReader object to encode the file into base64 and then transfer it to the server ~
Start to work.
The front end uses base64 to encode the file and transmits it to the server through ajax: