Page 1 of 1
Uploading pic To BLOB in Oracle
Posted: Tue Jun 21, 2005 8:02 am
by localhost
Code: Select all
$hndl=fopen($_REQUEST["imgfile"],"r");
$isize=sizeof($_REQUEST["imgfile"]);
$imgdata="";
while(!feof($hndl)){
$imgdata.=fread($hndl,$isize);
};
$imgdata=addslashes($imgdata);
$dbconn = @mysql_connect ("localhost", "root", "root") or exit("SERVER Unavailable");
@mysql_select_db("fi",$dbconn) or exit("DB Unavailable");
$sql = "INSERT INTO tblimage VALUES(NULL,'". $_REQUEST["imgtype"] ."','". $imgdata ."')";
@mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
mysql_close($dbconn);
fclose($hndl);
i have used this ode for uploading the image in Mysql database and it has worked fine but while using Oracle i got this error
OCIParse: ORA-00972: identifier is too long
Posted: Tue Jun 21, 2005 8:09 am
by Syranide
try posting the oracle code instead as it is the failing one, we really don't care about the code that works.
eitherway, I would guess your problem is your table, containing a column which has an improper size/type.
Posted: Tue Jun 21, 2005 8:12 am
by localhost
Code: Select all
if(isset($_FILES['questfile']['name']))
{
$types_array = array("image/jpeg","image/gif","image/pjpeg");
if (!in_array($_FILES['questfile']['type'], $types_array))
$error=1;
if ($_FILES['questfile']['size'] > 9000000 && $error==0)
$error=1;
$instr = fopen($_FILES['questfile']['tmp_name'],"rb");
$imagequestion = addslashes(fread($instr,filesize($_FILES['questfile']['tmp_name'])));
}
if(!isset($imagequestion))
$imagequestion="NULL";
if($count>0)
{
$query="insert into EX_MCSQ_QUESTION (QUESTION_ID,TOPIC_ID,QUESTION,OPTION_A,OPTION_B,OPTION_C,OPTION_D,OPTION_E,ANSWER,DIFF_LEVEL,DATE_ADDED,QUESTION_TYPE,QUESTION_PIC)
values (".($next+1).",$topic,'$question','$opta','$optb','$optc','$optd','$opte','$answer',$difficulty,to_timestamp('$d_date','YYYY-MM-DD'),1,'$imagequestion')";
$rs = OCIParse($conn,$query);
OCIExecute($rs);
}
Posted: Tue Jun 21, 2005 11:24 pm
by localhost
my column is set to be a CLOB but while uploading i get this error....please help needed urgent.
insert into EX_MCQ_QUESTION (QUESTION_ID,TOPIC_ID,QUESTION,OPTION_A,OPTION_B,OPTION_C,OPTION_D,OPTION_E,ANSWER,DIFF_LEVEL,DATE_ADDED,QUESTION_TYPE,QUESTION_PIC) values (1,3,'asdf asdf ','yes','no',NULL,NULL,NULL,'1',1,to_timestamp('2005-06-22','YYYY-MM-DD'),2,'ÿØÿà\0JFIF\0\0\0d\0d\0\0ÿþ\0Adobe ImageReadyÿì\0Ducky\0\0\0\0\0.\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0 ')
Warning: ociparse(): OCIParse: ORA-00972: identifier is too long in /wwwroot/htdocs/examination/grexamination/questions/addquestion.php on line 77
Posted: Wed Jun 22, 2005 12:17 am
by localhost
i got the solution for uploading...length of BLOB is 4000 characters...so when i tried to upload smaller images they were uploaded....but now the problem is how to display them...i am using this code..
Code: Select all
$Query = "Select * from EX_MCQ_QUESTION where QUESTION_ID=1";
$rs = OCIParse($conn,$Query);
OCIExecute($rs);
OCIFetchInto($rs, $row2, OCI_ASSOC);
$image=$row2["QUESTION_PIC"];
header("Content-Type: image/gif");
echo $image;
in output i am getting "OBject"
[SOLVED]
Posted: Wed Jun 22, 2005 2:16 am
by localhost
NO one replied so i solved it myself..
Code: Select all
$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) VALUES('.
MYBLOBID . ', EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
OCIBindByName($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
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);
}
else {
echo "Couldn't upload Blob\n";
}
$lob->free();
OCIFreeStatement($stmt);
Posted: Wed Jun 22, 2005 2:40 am
by Syranide
Well that's what you are supposed to do in the first place

Try to solve it yourself, if you are unable you ask, not because it didn't work

Posted: Wed Jun 22, 2005 2:49 am
by localhost
For displaying the image this is the code...
Code: Select all
$query = 'SELECT * FROM EX_MCQ_QUESTION WHERE QUESTION_ID = 1';
$stmt = OCIParse ($conn, $query);
OCIExecute($stmt, OCI_DEFAULT);
OCIFetchInto($stmt, $arr, OCI_ASSOC+OCI_RETURN_LOBS);
$result = $arr['OPTION_A_PIC'];
echo $result;
?>