Incorporating images with Oracle to create a PHP web site.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to write a web site for storing staff ID's together with
their photos using a PHP form. A user of the site should be able to
enter his ID, name, and select a file from a directory as his personal

Step 1. Created the table in SQL.
SQL> create table file_test (
        StaffID       number(5)  NOT NULL,
        StaffName      VARCHAR2(30),
        Staff_pic       bFile);

Step 2. Register a directory alias with Oracle.
SQL> CREATE DIRECTORY Staff_Images_Dir AS 'C:\Staff_Images';

Step 3. Insert some BFile names using PHP.
// etc.

// Build an INSERT for the BFILE names
$sql = "INSERT INTO file_test ( StaffID, StaffName, Staff_pic )
       VALUES ( '12345', 'Scott Tiger',
BFILENAME('Staff_Images_dir','12345.jpg') )";

$stmt = oci_parse($conn, $sql);

// Open the directory
$dir = 'C:\Staff_Images';
$dh = opendir($dir)
    or die("Unable to open $dir");

// Loop through the contents of the directory
while (false !== ( $entry = readdir($dh) ) ) {

    // Match only files with the extension .jpg, .gif or .png
    if ( is_file($dir.'/'.$entry) &&
preg_match('/\.(jpg|gif|png)$/',$entry) ) {

        // Bind the filename of the statement
        oci_bind_by_name($stmt, ":filename", $entry);

        // Execute the statement
        if ( oci_execute($stmt) ) {
            print "$entry added\n";


However, the above PHP code did not work, so I wrote the following
lines straight into SQL and I got 1 row created.

SQL> insert into file_test (StaffID, staff_name, staff_pic)
         values ('12345', 'Scott Tiger', BFILENAME('Staff_images_dir',

My questions.
1. How do I create a PHP code to let the user enter his details (ID and
name) in a form and select a file image (as his personal photo) from a
particular directory and save everything in the Database.
2. How do I go back then (as an admin) and view staff details and
pictures based on a SELECTed staff ID?

Any help will be highly appreciated.

Re: Incorporating images with Oracle to create a PHP web site.

On Sat, 06 May 2006 23:01:53 -0700, K. A. wrote:

Quoted text here. Click to load it

What was the problem? Did you get any errors? I'll probably be able  
to help you out, once you give me all the necessary information.

Quoted text here. Click to load it

Did that work?

Quoted text here. Click to load it

Here is a little ADOdb snippet that I wrote to solve precisely the
same problem. Uploaded the file to a CLOB field, which makes it possible
for me to have web server and Oracle instance on two different machines.

  <title>Upload File (ADOdb)</title>


  $INS="insert into poetry(file_desc,file_data)
        values (:pdesc,:cont)";

  try {
  catch (Exception $e) {

    <h2>File <?=$_FILES['file']['name']?>
     uploaded successfully!</h2>

I wholeheartedly advise you to use ADOdb as it is logical, reliable,
easy to use, covers different drivers and works with PHP5, which gives
you the ability to utilize exceptions.


Re: Incorporating images with Oracle to create a PHP web site.

Quoted text here. Click to load it

Harry Fuecks has an article on using LOBS and BFILE with Oracle at:

Christopher Jones, Oracle Corporation, Australia.

Site Timeline