超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<base64_decodeget_headers>
Last updated: Fri, 22 Jun 2007

base64_encode

(PHP 3, PHP 4 , PHP 5)

base64_encode -- 使用 MIME base64 对数据进行编码

描述

string base64_encode ( string data)

base64_encode() returns 使用 base64 对 data 进行编码。设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。

Base64-encoded 数据要比原始数据多占用 33% 左右的空间。

例子 1. base64_encode() 示例

<?php
  $str
= 'This is an encoded string';
  echo
base64_encode($str);
?>

此示例将显示:

VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==

参见 base64_decode()chunk_split()RFC 2045 6.8 章节。




add a note add a note User Contributed Notes
base64_encode
guy at bhaktiandvedanta dot com
02-Oct-2002 08:00
You can use base64_encode to transfer image file into string text and then display them. I used this to store my images in a database and display them form there. First I open the files using fread, encoded the result, and stored that result in the database. Useful for creating random images.

image.php:

<?

header(" Content-Type: image/jpeg");
header(" Content-Disposition: inline");
$sql = "SELECT data FROM image where name='".$img."'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$image = $row[0];
echo base64_decode($image);

?>

And in the html file you put:

<img src="image.php?img=test3" border="0" alt="">

Guy Laor

<base64_decodeget_headers>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22