高分求助!如何解决上传图片文件到数据库之后,再从数据库中读出来加载到页面以后却显示成乱码问题?急!!!

poul619 2004-04-14 07:24:51
我找到了一个例程用APACHE+PHP+oracle+WINXP_PRO把文件上传到数据库中。虽然没有把文件类型传递到数据库中,但是我已经在代码中加入了Header("Content-type: image/gif"); 语句,而且我也只是通过页面上传gif的图片。但是读取的时候还不能正常显示。代码如下:

上传部分 10.php文件:
<?php


if (!isset($_FILES['lob_upload'])) {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload">
<input type="submit" value="Upload">

</form>

<?php
}
else {

$myid = 1; // should really be a unique id e.g. a sequence number

$conn = OCILogon('manudata', 'smi619', 'manures');

// Delete any existing CLOB so the query at the bottom
// displays the new data

$query = 'DELETE FROM MYCLOB';
$stmt = OCIParse ($conn, $query);
OCIExecute($stmt, OCI_COMMIT_ON_SUCCESS);
OCIFreeStatement($stmt);

// Insert the CLOB from PHP's temporary upload area

$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn, 'INSERT INTO MYCLOB (C1, C2) VALUES('.
$myid . ', EMPTY_CLOB()) RETURNING C2 INTO :C2');
OCIBindByName($stmt, ':C2', $lob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);

// The function $lob->savefile(...) reads from the uploaded file.
// If the data was already in a PHP variable $myv, the
// $lob->save($myv) function could be used instead.
if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
OCICommit($conn);
echo "CLOB successfully uploaded\n";
}
else {
echo "Could not upload CLOB\n";
}
$lob->free();
OCIFreeStatement($stmt);
}

?>
显示图片页面 12.php文件 :

<? $conn = OCILogon('manudata', 'smi619', 'manures');
$query = 'SELECT C2 FROM MYCLOB WHERE C1 = 1';
$stmt = OCIParse ($conn, $query);
@OCIExecute($stmt, OCI_DEFAULT);
@OCIFetchInto($stmt, &$arr, OCI_ASSOC);
//Used with oci_fetch_all() and oci_fetch_array() to get an associative array as a result.
Header("Content-type: image/gif");

$result = $arr['C2']->load();
echo '<pre>';
echo $result;
echo '</pre>';
OCIFreeStatement($stmt);
OCILogoff($conn);
?>

上传E:\Apache\htdocs\apache_pb.gif文件之后在运行显示页面,出现下面的情况:
Warning: Cannot add header information - headers already sent by (output started at e:\apache\htdocs\12.php:1) in e:\apache\htdocs\12.php on line 7]
后面就是乱码了。

恳请大侠们帮忙!高分求助!

...全文
131 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccterran 2004-04-15
  • 打赏
  • 举报
回复
你是二进制读入到数据库中?应该不会啊
xuzuning 2004-04-15
  • 打赏
  • 举报
回复
Warning: Cannot add header information - headers already sent by (output started at e:\apache\htdocs\12.php:1) in e:\apache\htdocs\12.php on line 7]

在12.php第1行处有输出

按你贴出的样子
上传部分 10.php文件:
<?php


显示图片页面 12.php文件 :

<? $conn = OCILogon('manudata', 'smi619', 'manures');

你的第1行是空行
poul619 2004-04-15
  • 打赏
  • 举报
回复
另外,如何判断文件有没有上传完毕啊?我上传了1个word文档(800多k ),可时下在以后只有13k?怎么解决这个问题啊?
poul619 2004-04-15
  • 打赏
  • 举报
回复
well,my project is to build a database of standard parts of machinery,so there are many pictures both gif\jpeg\3ds\prh etc.,maybe there are 100000 pictures!and I need to set up on another oracle database.so I want to do thi by upload the file to database.
xylegend 2004-04-15
  • 打赏
  • 举报
回复
mark
52juanjuan 2004-04-15
  • 打赏
  • 举报
回复
晕,用存地址的方法,即方便有省代码,一举n得,何不去做做?
poul619 2004-04-15
  • 打赏
  • 举报
回复
well, I put "@",at the beginning of these rows
$conn = OCILogon('manudata', 'smi619', 'manures');
$query = 'SELECT C2 FROM MYCLOB WHERE C1 = 1';
$stmt = OCIParse ($conn, $query);
then,I will never meet with such warning,but stll can not display the gif,who can tell me why?
poul619 2004-04-15
  • 打赏
  • 举报
回复
header前面没有任何输出啊,我也不知道怎么回事。就是header加载不了。但是如果取消和header语句,上传txt文件是可以浏览器中显示的,除此之外,所有的文件都是乱码。
unixdotnet 2004-04-14
  • 打赏
  • 举报
回复
header前不能有空格、输出还有检查调用12.php的文件有没有违反这个规则。
xiaodong1981 2004-04-14
  • 打赏
  • 举报
回复
为什么要这样呢 数据库存储地址不是方便吗
ccterran 2004-04-14
  • 打赏
  • 举报
回复
不会吧. <? $conn 前面有什么输出或空格吗?导致 Header("Content-type: image/gif"); 失效了

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧