Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045~RFC2049,上面有MIME的详细规范。Base64编码可用于在HTTP环境下传递较长的标识信息。例如,在Java Persistence系统Hibernate中,就采用了Base64来将一个较长的唯一标识符(一般为128-bit的UUID)编码为一个字符串,用作HTTP表单和HTTP GET URL中的参数。在其他应用程序中,也常常需要把二进制数据编码为适合放在URL(包括隐藏表单域)中的形式。此时,采用Base64编码具有不可读性,即所编码的数据不会被人用肉眼所直接看到。

string base64_decode ( string $encoded_data )

1.base64_encode()接受一个参数,也就是要编码的数据(这里不说字符串,是因为很多时候base64用来编码图片)

2.base64_encode()为双向加密,可用base64_decode()来解密

/*先总结一下常见的urlencode()的转换字符?=> %3F= => %3D% => %25& => %26\ => %5C+ => %2B
空格 => +
*/file.php<pre name="code" class="html"><?php
header('content-type:text/html;charset=utf-8');
$url = 'http://localhost/Eight/lianxi/get_img/img/make.bmp';
$string = file_get_contents($url);
$content = base64_encode($string);
//echo $content;die;?>
<a href="http://localhost/Eight/lianxi/get_img/get.php?content=<?php echo $content ?>">点击提交</a>

get.php

<?php

 

header('content-type:text/html;charset=utf-8');
$con = $_GET['content'];
//echo $con;die;
$file = str_replace(' ','+',$con);
$img = base64_decode($file);
file_put_contents('./img/now.bmp',$img);