|
<br> //store.php <BR><HTML> <BR><HEAD><TITLE>Store binary data into Oracle Database</TITLE></HEAD> <BR><BODY> <BR><BR><?php <BR>// 如果提交了表单,代码将被执行: <BR>dl("php_oci8.dll"); <BR>$conn = OCILogon("scott","tiger"); <BR>if ($submit) { <BR><BR>echo "File name: <b>$userfile_name</b><br> "; <BR>echo "File size: <b>$userfile_size</b><br> "; <BR><BR>$hwsize = GetImageSize($userfile ); <BR>$w = $hwsize[0]; <BR>$h = $hwsize[1]; <BR>echo "Image width: <b>$w</b><br> "; <BR>echo "Image height: <b>$h</b><br> "; <BR><BR>$ImgType = strtolower(substr( strrchr_( $userfile_name, "." ), 1 ) ); <BR>if ($ImgType == "jpg") <BR> $ImgType = "jpeg"; <BR>echo "Image type: <b>$ImgType</b><br> "; <BR><BR>echo "Created date; <b>".date('Y-m-d')."</b><br> "; <BR><BR><BR>$sql = "insert into <BR> icture (PicId, UserName, Width, Height, ImgSize, ImgType, Created, Image, FileName, Description) <BR>values(PicturePicId.nextval, '$username', $w, $h, '$userfile_size', '$ImgType', TO_DATE('".date('Y-m-d')."','YYYY-MM-DD'), EMPTY_BLOB(), '$userfile_name', '$description') <BR>returning Image into :Image"; <BR><BR>echo "<pre>$sql</pre>"; <BR>$stmt = OCIParse($conn, $sql ); <BR><BR>$Image = OCINewDescriptor($conn ); <BR><BR>OCIBindByName($stmt, ":Image", $Image, -1, SQLT_BLOB ); <BR><BR>if (!OCIExecute($stmt, OCI_DEFAULT)) { <BR> echo "Execution failed"; <BR> exit(1); <BR>} <BR><BR>$fp = fopen($userfile, "r" ); <BR>$Image->save(fread($fp, filesize($userfile ) ) ); <BR>fclose($fp ); <BR>OCICommit($conn ); <BR><BR>OCIFreeStatement($stmt ); <BR><BR>} else { <BR>?> <BR> <form method="post" action=" <?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <BR> File Description:<br> <BR> <input type="text" name="description" size="40"> <BR> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"> <BR> <br>File to upload/store in database:<br> <BR> <input type="file" name="userfile" size="40"> <BR> <p><input type="submit" name="submit" value="submit"> <BR> </form> <BR><BR><?php <BR>} <BR>?> <BR></BODY> <BR></HTML> <BR>//display.php <BR><?php <BR>/* <BR> Purpose: <BR> Display an image from 'Picture' table <BR>*/ <BR>dl("php_oci8.dll"); <BR>$conn = OCILogon("scott","tiger"); <BR>$stmt = OCIParse($conn, "select Image, ImgType from Picture where picid=23" ); <BR>OCIExecute($stmt); <BR><BR>@OCIFetchInto($stmt, &$result, OCI_ASSOC); <BR>Header("Content-type: image/".$result['IMGTYPE']); <BR>echo $result['IMAGE']->load(); <BR><BR>OCILogoff($conn ); <BR>?> <br><br> |
|