Can someone please let me know, how to upload/insert images into Oracle database using PHP pages. Thanks in advance.

    try this,
    first make a table which will store the image, in mysql the column type is logblob(check the same for oracle)

    use this before storing the image
    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

    where $form_data is the path of file to store.
    also, the for shud have this attribute
    enctype="multipart/form-data"

    then send $data and $form_data_type to table.This variable $form_data_type is made available by PHP so just save it as it is.

    for retrieving

    read the column back alongwith the data type.
    and do this:
    // $type is the form_data_type
    Header( "Content-type: $type");
    echo $data;
    it shud work!

      (Yes, I am following up to my own posting.)
      Thanks your immediate response. I tried to solve the problem using the method given by you. But it's not working with oracle. Any how i found the solution for the same. I am attaching the sample code here for reference to PHP programmers.

      Here two php files are there.

      one file is:-uploaimage.php

      second file is:-display.php

      The first file which will take the input (the image you want upload. You can upload any image file. but display.php is limited to .gif file only)from the client browser and is going to submit to the same page,  which is going to store the images in oracle database. The second file display all those images(.gif only) in the client browser. 

      uploadimage.php follows here.

      <HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
      <BODY>
      <?php
      if ($submit) {
      $data = fread(fopen($form_data, "r"), filesize($form_data));
      //You have to pass Appropriate username, Password,Serveice name
      $db = OCILogon("scott","tiger","grk");
      $stmt = OCIParse($db,"insert into blob_table values ($id,EMPTY_BLOB()) returning id,IMG into :id,:lob");
      $lob = OCINewDescriptor($db);
      OCIBindByName($stmt,":ID",$id,32);
      OCIBindByName($stmt,":LOB",$lob,-1,SQLT_BLO😎;
      // we cannot use autocommitt here
      $exec_result=OCIExecute($stmt,OCI_DEFAULT);
      $lob->save($data);
      echo "$form_data id:$id\n";
      OCICommit($db);
      if(!$exec_result){
      print "Error Occured".OCIError($conn);
      }else{
      OCICommit ($db);
      print "<p>This file has been uploaded into Database ";
      }
      } else {
      ?>
      <form method="post" action="uploadimage.php" enctype="multipart/form-data">
      File Description:<br>
      <input type="text" name="id" size="40">
      <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
      <br>File to upload/store in database:<br>
      <input type="file" name="form_data" size="40">
      <p><input type="submit" name="submit" value="submit">
      </form>
      <?php
      }
      ?>
      </BODY>

      display.php follows here.

      <body>
      <?
      //You have to pass Appropriate username, Password,Serveice name
      $db = OCILogon("scott","tiger","grk");
      $stmt = OCIParse($db,"select * from blob_table order by id");
      OCIExecute($stmt);
      $img='';
      $count=0;
      while (OCIFetchInto($stmt,$arr,OCI_ASSOC)) {
      $count++;
      echo "id: ".$arr[ "ID" ]."\n";
      $img= ($arr[ "IMG" ]->load());
      if($fp = fopen ("test".$count.".gif", "w")){
      fwrite ($fp, $img);
      echo"&nbsp;<img src=\"test".$count.".gif\"><br><hr>";
      }else{
      echo ("failed to open the file");
      }
      }
      ?>
      </body>

      I hope it will help other programs.

      thanks

        Write a Reply...