This article to the students to introduce an article about the PHP Base64 encoded file binary stream main use where, a friend can refer to, only a brief description of a bit.
BASE64 encoded file binary streams are encoded using the Base64_encode function to encode the binary information of the file.
Official notes
base64_encode-encoding data using MIME base64
Report a bug description
String Base64_encode (String $data)
Use base64 to encode data.
This encoding is designed so that binary data can be transmitted through a non-pure 8-bit transport layer, such as the body of an e-mail message.
base64-encoded data takes up about 33% more space than the original data.
The specific methods are:
The code is as follows |
Copy Code |
$path = ' image.jpg '; $fp = fopen ($path, ' RB '); Open a file in binary form $content = Fread ($fp, FileSize ($path)); Read File contents Fclose ($FP); $content = Base64_encode ($content); Encode binary information into a string Echo $content; The results of the above program output are similar: R0lgodlheaaqajecaisehaaahp///waaach5baeaaaialaaaaaaqabaaaaimli +pyxedqadqhvflpfak30jg1lwmqigwl6cclmkhxn6mdvb6zhcaow== |
This allows us to successfully convert a file into a string.
The decoding process is very simple, using Base64_decode ($content).
The main uses of the above processing procedures are:
1. Interface transmission
The main application is to transfer files from one site to another through the Web interface, which can be used for XML information.
2. Deposit into the database
Of course, storing file information such as pictures in a database is completely not necessary, but this approach still applies. This approach is more acceptable for novice database users. Because this is exactly a string.
3. File encryption
File encryption can be used less, for example, if we have a PHP program need to protect, must have authorization code for the user to function properly, then we may use the authorization code to encrypt the file, the above encoded string is processed again. The operating procedure requires an authorization code to run.
Of course there are other uses that are flexible to suit the needs of everyone.
http://www.bkjia.com/PHPjc/632665.html www.bkjia.com true http://www.bkjia.com/PHPjc/632665.html techarticle This article to the students to introduce an article about the PHP Base64 encoded file binary stream main use where, a friend can refer to, only a brief description of a bit. BASE64 encoded Files ...