Page 1 of 1

ORACLE: LONG RAW

Posted: Mon Mar 31, 2003 12:22 pm
by frosero
:?: Hi Everybody. Please help me with this.

I try to show an image in my web page but this image is in a LONG RAW column in an Oracle table, when i do it with classic OCIFetch, i get a hundred of rare characters, in place of the real gif/jpg image.

What can i do?

Thank u.

Posted: Mon Mar 31, 2003 1:39 pm
by twigletmac
Could we see some of the code you use for retrieving and displaying the image?

Mac

Posted: Mon Mar 31, 2003 5:19 pm
by frosero
twigletmac wrote:Could we see some of the code you use for retrieving and displaying the image?

Mac

Hi twigletmac. Thanks for your anser. I use this function (query) to retrieve data. THEN basically, when i get the data (whichever type it be) i show it using 'ECHO' instruction. Echo works fine with numbers, strings, dates, but when data type is LONG RAW it shows a group of 'rare characters'.

Here is the function:

function query($Pv_Query, $Pv_EsTrans=FALSE, $Pa_VarQuery=array()) {
/*Executes a query, we use 3 parameters: first one is the string of the query,*/
/*the second one is TRUE/FALSE, indicating if it is a transaction or a select, */
/*third one is an array of a parameters for the query, it has Oracle variables*/
/*as keys, and data are Php variables*/

$La_Result = array();
$La_Result["error"] = TRUE;

$Ln_Stmt = @OCIParse($this->get_cx(), $Pv_Query);

// if a parsing error, we register the error
if (! $Ln_Stmt) {
$err = OCIError($this->get_cx());
$this->error = "Parsing:".$err[ "code" ].":".$err[ "message" ]."\n";
}

// if an execution error, it generates an error and stops
else{
if ( count($Pa_VarQuery) ) {
$La_Valores = array();
$j = 0;
for ($i=0; $i<count($Pa_VarQuery); $i++)
{
list($Lv_OciVar,$PhpVar) = each($Pa_VarQuery);
$La_Valores[$j] = $PhpVar;
OCIBindByName($Ln_Stmt, $Lv_OciVar, $La_Valores[$j]);
$j++;
}
}

if (! @OCIExecute($Ln_Stmt)) {
$err = OCIError($Ln_Stmt);
$this->error = "Ejecución:".$err[ "code" ].": ".$err[ "message" ]."\n";
//echo $Pv_Query;
echo $this->error;
}

else{
// no transaction nor parsing error

$La_Result["error"] = FALSE;

//DATA extraction, if it's not a transaction
if (! $Pv_EsTrans ){
while ( OCIFetchInto($Ln_Stmt,&$La_Valores, OCI_ASSOC+OCI_RETURN_NULLS) ) {
$La_Result["valores"][] = $La_Valores;
}
}
}
}
return $La_Result;
}

To show the image i just do:
echo "Image ".$La_Result["valores"][0]["PHOTO"];

Please tell me.

Posted: Mon Mar 31, 2003 6:38 pm
by hedge
You need to send a header to the browser to tell it to expect an image

ie.
header('content-type: image/jpeg');
echo <binary data>

Posted: Wed Apr 02, 2003 9:26 am
by frosero
:?
Hi.
Please tell me one thing, why, when is used header() (what u recommended), i got an error that says that 'a header is already defined: cannot add headers' and this error points to the first line of PHP: '<?php'.


Tell me if i defined a header in HTML, is it good like this:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="image/jpeg">
</HEAD>
<BODY>
<?php
/*procedures to select the image*/
echo <binary data>;
?>
</BODY>
</HTML>

Is this correct to get my BLOB image?

Posted: Wed Apr 02, 2003 12:52 pm
by hedge
It's because you've already sent content to the browser. You aren't going about it the correct way. You have to think of it as two seperate connections between the browser and your webserver.

first connection to get the html, second connection to get the image. Do it like this:

phpScript: getimage.php

Code: Select all

<?php
 header ('content-type: image/jpeg');
/*procedures to select the image*/ 
echo <binary data>; 
?>
html page

Code: Select all

<html>
<body>
 <img src="getimage.php">
</body>
</html>
browser points to html page.