i have proble of storing image in oracle databse,
i am using oracle 8.1.6./php4/linux

i want to store image in BLOB field and shown in browser..

pl.help me for that ..

if any one have answer of my problem write me immediately.

thanks in advance ..

bye

    why don't you store the filenames in the database, and reference the actual files that way?

    I'm sure it's faster, and puts less load on the database.

    prathesh wrote:

    i have proble of storing image in oracle databse,
    i am using oracle 8.1.6./php4/linux

    i want to store image in BLOB field and shown in browser..

    pl.help me for that ..

    if any one have answer of my problem write me immediately.

    thanks in advance ..

    bye

      r u 100% ok.

      but i want to stroe image in database only (as per my requirement)

      and i am strickly using oracle and it has facility like BLOB,BFILE.

      but i don't know how to use with php.

      pl.read thia and possible answer if u know pl.

        okay, you could try this:

        1)read the data into PHP as normal, then send a header along the lines of:

        header("Document-type: image/gif\n\n");

        or somesuch depending on the type of image you are using.

        Then echo the data you have got from the db connect. this should tell the browser to accept the following data as an image.

        This will only work if you are using the page as a standalone image,- as it uses a header.

        to use this sensibly, you could try something like:

        <img src="generateimage.php?id=10203" alt="The image"></IMG>

        then using generateimage.php to call the database, get the data, and use the header to tell the browser to accepot the following data as an image.

        don't see why that wouldn't work, although i have never tried it.... 🙂

        cheers,

          the following code which i am trying

          $db1 = OCILogon("cms","cms");
          $sqlselect="select image_file from test_image";
          $stmt1=OCIParse($db1,$sqlselect);

          OCIExecute($stmt1);
          
          while(OCIFetchInto($stmt1,$data,OCI_NUM+OCI_RETURN_LOBS))
          {
          	$records = $data[0];
          }

          Header( "Document-type: image/gif\n\n");
          echo $records;
          }

          the result of this script is /tmp/phplBzJmD, that means it shows temporary storage path of image....

          pl. read the above code and if possible help for the same ..

          thanks in advance..

            hmmm, you could check out the fpassthru() functions -

            open the temporary file it gives you, then use passthru to pipe the data through the current script.- after the gif type header.

            hth

              actually the problem is where ever it showing path of file /tmp/phpXXXX

              but actually file is not stored at that location and with out that how can use file pointer (fp)

              pl.read the same and do favour for me if possible

              bye for now.

              take care.

                3 months later

                $dbcon = OCILogon($dbUser,$dbPassword,$dbName);
                $lob = OCINewDescriptor($dbcon, OCI_D_LO😎;
                $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 IMAGE_DATA into :img_blob";
                $stmt = OCIParse($dbcon,$query);
                OCIBindByName($stmt, ':img_blob', &$lob, -1, OCI_B_BLO😎;
                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

                  Write a Reply...