Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Insert Image using plsql procedure

416879Mar 15 2004 — edited Aug 2 2005
Hi,

I need to insert image,pdf,doc files using procedures and php scripts.I have tried few of the thing from forum but no one has done it using procedure.

I have successfully created a package but when I am trying to insert it's not working.

My Package collection_pkg reads:
//--------------------------------------------------------
CREATE OR REPLACE PACKAGE collection_pkg AS

PROCEDURE add_collection(
v_collection_name collections.collection_name%TYPE,
v_collection_desc collections.collection_desc%TYPE,
v_collection_image collections.collection_image%TYPE
);

END collection_pkg;
/

CREATE OR REPLACE PACKAGE BODY collection_pkg AS

PROCEDURE add_collection(
v_collection_name collections.collection_name%TYPE,
v_collection_desc collections.collection_desc%TYPE,
v_collection_image collections.collection_image%TYPE
) IS
BEGIN
INSERT INTO collections
(
collection_id,collection_name,collection_desc,collection_image
)
VALUES
(
collection_id.NextVal,v_collection_name,v_collection_desc,v_collection_image
);
END add_collection;

END collection_pkg;
/
commit;
//--------------------------------------------------------My PHP Script reads :

function AddCollection() {
global $HTTP_POST_VARS,$conn,$HTTP_COOKIE_VARS,$HTTP_POST_FILES,
$msg_collection_insert_success,$collection_image,$collection_image_name,
$msg_collection_insert_failure,
$msg_duplicate_collection_exists;


$collection_image = $HTTP_POST_FILES[collection_image]['name'];
$collection_image_name = $HTTP_POST_FILES[collection_image]['tmp_name'];
$collection_image_size = $HTTP_POST_FILES[collection_image]['size'];
$collection_image_type = $HTTP_POST_FILES[collection_image]['type'];

$binary_junk = addslashes (fread(fopen($collection_image_name, "r"), filesize($collection_image_name)));

$collection_name = trim($HTTP_POST_VARS[collection_name]);
$collection_desc = trim($HTTP_POST_VARS[collection_desc]);

# Insert in to database
$stmt = OCIParse($conn,"begin collection_pkg.add_collection(:collection_name, :collection_desc, :collection_image); end;");

OCIBindByName($stmt,":collection_name",&$collection_name,100);
OCIBindByName($stmt,":collection_desc",&$collection_desc,100);
OCIBindByName($stmt,":collection_image",&$binary_junk,-1);

OCIExecute($stmt);
if(OCIRowCount($stmt) > 0) {
$msg = $msg_collection_insert_success;
} else {
$msg = $msg_collection_insert_failure;
exit;
}

OCIFreeStatement($stmt);
# Back to Collection Menu
CollectionList($msg);
} # End of Function

I am using oracle9i and blob field to store the image.

Please reply asap.

Thanks in advance.

Regards,
sachin.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2005
Added on Mar 15 2004
14 comments
6,117 views