1 Reply Latest reply on May 3, 2013 11:30 PM by cj

    how to load folder with images php with oracle

      Hi i want to upload from my php form folder with images what should i fix in my php code for 1 image?


      define("ORA_CON_UN", "obrazy");
      define("ORA_CON_PW", "miksas1");
      define("ORA_CON_DB", "//localhost/orcl");

      if (!isset($_FILES['lob_upload'])) {

      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
      Image filename: <input type="file" name="lob_upload">
      <input type="submit" value="Upload">

      else {

      $conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

      // Insert the BLOB from PHP's tempory upload area

      $lob = oci_new_descriptor($conn, OCI_D_LOB);
      $stmt = oci_parse($conn, 'INSERT INTO FOTKI (FOTKAID, FOTKA) '
      oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
      oci_bind_by_name($stmt, ':FOTKA', $lob, -1, OCI_B_BLOB);
      oci_execute($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'])) {
      echo '<p>Obrazek załadowano</p>';
      else {
      echo "Couldn't upload Blob\n";

      oci_close($conn); // log off

        • 1. Re: how to load folder with images php with oracle
          If I understand correctly you want to convert that script to upload
          multiple images?

          Once you know the filenames, you can use code like that below:
          // drop table mybtab;
          // create table mybtab (blobid number, blobdata blob);
          $c = oci_connect('cj', 'secret', 'localhost/orcl');
          if (!$c) {
              $m = oci_error();
              trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
          $sql = 'delete from mybtab';
          $s = oci_parse ($c, $sql);
          $e = oci_execute($s, OCI_COMMIT_ON_SUCCESS);
          $lob = oci_new_descriptor($c, OCI_D_LOB);
          $sql = 'insert into mybtab (blobid, blobdata) values(:myblobid, :blobdata)';
          $s = oci_parse($c, $sql);
          oci_bind_by_name($s, ':myblobid', $myblobid);
          oci_bind_by_name($s, ':blobdata', $lob, -1, OCI_B_BLOB);
          // Load first image
          $myblobid = 1;
          $myv = file_get_contents("/tmp/oraclelogo.jpg");
          $lob->writeTemporary($myv, OCI_TEMP_BLOB);
          oci_execute($s, OCI_NO_AUTO_COMMIT);
          // Load second image
          $myblobid = 2;
          $myv = file_get_contents("/tmp/unbreaklinux.jpg");
          $lob->writeTemporary($myv, OCI_TEMP_BLOB);
          oci_execute($s, OCI_NO_AUTO_COMMIT);
          Note this only parses once.

          I used a temporary lob but you could convert your RETURNING INTO code
          to similarly insert multiple values. Also see