PHP从MySQL中读Gif图片数据时出现乱码,请指教错误原因
我想在MySQL中存取图片,数据库名为binary_data,表名binary_data,bin_data是LongBlob字段,id=2是一幅Gif
图片,已存进了MySQL
我运行以上程序,却出现以下错误,图片是乱码,无法正确显示,请多指教。
我使用的是WinXp+php-4.3.4-win+IIS 5.0+mysql-4.0.16-win
错误提示:
Connected successfully Warning: Cannot modify header information - headers already sent by
(output started at F:\software\PHP\display.php:5) in F:\software\PHP\display.php on line 10
GIF89a??????????????... //ʽ¾ݿ≺³ɽű
为方便您跟踪问题,我把数据库结构生成脚本及图片插入脚本贴在了下面。
//数据库结构生成脚本
/*==============================================================*/
/* Database name: binary_data */
/* DBMS name: mysql-4.0.16-win */
/* Created on: 2003-12-3 10:52:57 */
/*==============================================================*/
drop index "PRIMARY" on binary_data;
drop table if exists binary_data;
/*==============================================================*/
/* Table: binary_data */
/*==============================================================*/
create table if not exists binary_data
(
id integer(4),
bin_data blob,
filetype varchar(100),
filename varchar(50),
primary key (id)
);
/*==============================================================*/
/* Index: "PRIMARY" */
/*==============================================================*/
create unique index "PRIMARY" on binary_data
(
id
);
//图片插入脚本
<?php
/* 连接选择数据库 */
$link = mysql_connect("localhost", "root", "")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("binary_data") or die("Could not select database");
$file = "c:\\image.gif";
$data=addslashes(fread(fopen($file,"rb"),filesize($file)));
$result=MYSQL_QUERY("INSERT INTO binary_data(bin_data,filename) values('$data','$file')");
$id=MYSQL_insert_id();
print "This file has the following id: $id";
mysql_free_result($result);
/* 断开连接 */
mysql_close($link);
?>