PHP Base64 encoded file binary stream main use _php tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.