|
Posted by K. A. on 05/07/06 09:01
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
photo.
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.
<?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',
'12345.jpg'));
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.
Navigation:
[Reply to this message]
|