store and retrieve a (jpg) picture into a blob field ?

          Posted on 2006-01-11 10:33 風清云淡 閱讀(151) 評論(0)  編輯  收藏 所屬分類: PHP
           Jun 13th, 2003 15:18
          Peter Theill, Andi Worx, Patrick Mahla,


          $dbcon = OCILogon($dbUser,$dbPassword,$dbName);
          $lob = OCINewDescriptor($dbcon, OCI_D_LOB);
          $data = fread(fopen($form_data, "r"), filesize($form_data));
          $query = "insert into IMAGE_DATA (";
          $query .= "NUM_IMAGEID, STR_IMAGE_TYPE, BLO_IMAGE_DATA";
          $query .= ") values (";
          $query .= "NUM_ID.NEXTVAL, $form_data_type, EMPTY_BLOB()";
          $query .= ") returning BLO_IMAGE_DATA into :img_blob";
          $stmt = OCIParse($dbcon,$query);
          OCIBindByName($stmt, ':img_blob', &$lob, -1, OCI_B_BLOB);
          if (OCIExecute($stmt,OCI_DEFAULT)) {
          if($lob->save($data)){
          OCICommit($dbcon);
          OCIFreeStatement($stmt);
          echo "Blob successfully uploaded\n";
          }else{
          OCIFreeStatement($stmt);
          echo "Couldn't upload Blob\n";
          }
          }
          OCILogoff($dbcon);

          --------------------------------------------------------------

          If you use this Codesnippet, you can store BLOB to an oracledb!
          The next Codesnippet you can view the images!

          -------------------------------------------------------------

          $dbcon = OCILogon($dbUser,$dbPassword,$dbName);
          $query = "select * from IMAGE_DATA where NUM_ID=$id";
          $stmt = OCIParse($dbcon, $query);
          OCIExecute($stmt, OCI_DEFAULT);
          while (OCIFetchInto($stmt, $row, OCI_ASSOC)) {
          $data = $row["BLO_IMAGE_DATA"]->load();
          }
          $type = OCIResult($stmt,"STR_IMAGE_TYPE");
          OCIFreeStatement($stmt);

          Header( "Content-type: $type");
          echo $data;

          cu
          AndiWorx

           


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 1, comments - 0, trackbacks - 0, articles - 3

          Copyright © 風清云淡

          主站蜘蛛池模板: 页游| 宁城县| 南京市| 双峰县| 岳阳市| 天祝| 饶平县| 青田县| 台南市| 铁岭县| 高密市| 五指山市| 读书| 长岛县| 三原县| 青河县| 博客| 新和县| 黔南| 东光县| 东丽区| 彩票| 礼泉县| 巴中市| 泗洪县| 台北县| 钟祥市| 东至县| 开江县| 高陵县| 镇坪县| 桂阳县| 镶黄旗| 龙陵县| 宁德市| 淮阳县| 玉树县| 宁波市| 五大连池市| 靖安县| 招远市|