高分求助!如何解决上传图片文件到数据库之后,再从数据库中读出来加载到页面以后却显示成乱码问题?急!!!
我找到了一个例程用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]
后面就是乱码了。
恳请大侠们帮忙!高分求助!