关于php:为什么在传输之前需要base64编码图像?

Why do we need to base64 encode images before transmitting?

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
What is the use of base 64 encoding?

我见过许多代码片段,base64在通过HTTP协议传输之前对图像进行编码。

我想知道为什么我们需要它?


这不是必需的,但它使您能够在不执行附加HTTP请求的情况下嵌入图像(在某些情况下,这是不可能或不允许的)。


从base64上的维基百科条目:

The term Base64 refers to a specific
MIME content transfer encoding. It is
also used as a generic term for any
similar encoding scheme that encodes
binary data by treating it numerically
and translating it into a base 64
representation. The particular choice
of base is due to the history of
character set encoding: one can choose
a set of 64 characters that is both
part of the subset common to most
encodings, and also printable. This
combination leaves the data unlikely
to be modified in transit through
systems, such as email, which were
traditionally not 8-bit clean.

特别是关于HTTP:

Base64 encoding can be helpful when
fairly lengthy identifying information
is used in an HTTP environment. For
example, a database persistence
framework for Java objects might use
Base64 encoding to encode a relatively
large unique id (generally 128-bit
UUIDs) into a string for use as an
HTTP parameter in HTTP forms or HTTP
GET URLs. Also, many applications need
to encode binary data in a way that is
convenient for inclusion in URLs,
including in hidden web form fields,
and Base64 is a convenient encoding to
render them in not only a compact way,
but in a relatively unreadable one
when trying to obscure the nature of
data from a casual human observer.


HTTP协议不能保证是"8位干净的",因此它可能会损坏二进制流。