Home >Backend Development >PHP Tutorial >PHP Base64 encoded file binary stream is mainly used_PHP tutorial
This article will introduce to you an article about where the binary stream of php Base64 encoded files is mainly used. Friends who are interested can refer to it. I will only briefly describe it.
Base64 encoded file binary stream uses the base64_encode function to encode file binary information.
Official description
base64_encode — Encode data using MIME base64
Report a bug Description
string base64_encode ( string $data )
Encode data using base64.
This encoding is designed to enable binary data to be transmitted over non-pure 8-bit transport layers, such as the body of an email.
Base64-encoded data takes up about 33% more space than the original data.
The specific method is:
The code is as follows
|
Copy code
|
||||
$path = 'image.jpg'; $fp = fopen($path, 'rb'); // Open the file in binary form$content = fread($fp, filesize($path)); // Read file content fclose($fp);$content = base64_encode($content); // Encode binary information into a string // echo $content; The output of the above program is similar to: R0lGODlhEAAQAJECAISEhAAAhP///wAAACH5BAEAAAIALAAAAAAQABAAAAImlI +pyxedQADQhVflpfAK30jG1lwmqIgWl6CClmKHxn6mdVb6zhcAOw==
In this way we successfully converted a file into a string. The decoding process is very simple, just use base64_decode($content). | The main purposes of the above processing process are:
Mainly suitable for transferring files from one site to another through the WEB interface, and can be used for XML information.
http://www.bkjia.com/PHPjc/632665.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632665.htmlTechArticleThis article will introduce to you an article about where the binary stream of php Base64 encoded files is mainly used. There are some examples. Friends can refer to it, I just briefly described it. Base64 encoded file...