【问题标题】:show oracle blob image in PHP or ASP在 PHP 或 ASP 中显示 oracle blob 图像
【发布时间】:2011-09-28 14:15:22
【问题描述】:

我尝试从 Oracle 10g 数据库加载 blob 映像。我在 .ASP VB 和 .PHP 中都试过了。

 TABLE = STD_IMAGE
 Name                            Null?    Type
 ------------------------------- -------- ----
 IMG_ID_NO                       NOT NULL NUMBER(10)
 IMG_IMAGE                       NOT NULL BLOB

ASP 代码

 <%@ LANGUAGE="VBSCRIPT" %>
 <%Option Explicit
 Dim Rs, sSQL, OBJdbConnection
 ' Clear out the existing HTTP header information
 Response.Expires = 0
 Response.Buffer = TRUE
 Response.Clear
 'Change the HTTP header to reflect that an image is being passed.
 Response.ContentType = "image/jpg"
 Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
 OBJdbConnection.Open "Provider=OraOLEDB.Oracle;Data Source=xxxxxx;User Id=xxxx;Password=xxxxx;"
 DIM itemID
 itemID = request.querystring("InventoryItemId")
 itemID = 25
 sSQL = "Select * from std_image where IMG_ID_NO=25"
 set rs = OBJdbConnection.Execute(sSql)
 If not rs.eof Then
 Response.BinaryWrite rs("IMG_IMAGE")
 Response.End
 End If
 CloseRecordset(rs)%>
 <%Set OBJDbConnection = nothing%>

PHP 代码

 <?php   
 $db ="(DESCRIPTION =
 (ADDRESS =
     (PROTOCOL = TCP)
     (HOST = xxxxxx)
     (PORT = 1522)
  )
   (CONNECT_DATA = (SID = xxxxx))
   )";

$odbc = ocilogon ('xxxxxx', 'xxxxxx', $db) or die( "Could not connect to Oracle database!") or die (ocierror());

$sql = "SELECT IMG_IMAGE FROM std_image WHERE IMG_ID_NO = 25";  
$stid = ociparse($odbc, $sql);

ociexecute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
if (!$row) {
    header('Status: 404 Not Found');
} else {
    $img = $row['IMG_IMAGE']->load();
    header("Content-type: image/jpg");
    print $img;
}
    ?>

对于这两个示例,我都会收到以下消息:

 The image “http://localhost/test_ShowImage.asp” cannot be displayed because it contains errors.  
 The image “http://localhost/test_getImage.php” cannot be displayed because it contains errors.

【问题讨论】:

  • 这里有一些很好的信息:aspupload.com/manual_db.html
  • 您确定数据库中的 blob 数据是有效图像吗?
  • 是的,它已经在后台运行了。 Backoffice 采用 oracle6i 形式。它通过 oracle 表单存储在 dbase 中,并在表单或报告中检索。
  • 尝试使用(例如)Firebug 或 Fiddler 查看来自服务器端脚本的响应。那里可能有指向问题的信息。

标签: php html oracle asp-classic blob


【解决方案1】:

我使用您的代码作为我的代码的基础,并且它有效。不过我使用了 PHP ADODB 库。

include("settings.php"); //includes db connection

$docid = $_REQUEST['document_id'];

$sql = "SELECT DOCUMENT_FILE FROM ACCOUNTS_DOCUMENTS WHERE DOCUMENT_ID = ".$docid;
$rs = $db->Execute($sql);
header("Content-type: image/jpg");
print $rs->fields['DOCUMENT_FILE'];

【讨论】:

    猜你喜欢
    • 2017-07-28
    • 2018-07-06
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2018-01-23
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多