代码:-------------------------------------------------------------------------------- @$oracle_home/rdbms/admin/owaload.sql 使用ie对oracle http server 中的modpl/sql实施配置 Database Access Descriptor Name updown Schema Name scott Oracle User Name scott Oracle Password scott Oracle Connect String <- found in your tnsnames.ora Document Table scott.documents Document Access Procedure scott.cntsample.download
CONNECT Samples/Samples
SET DEFINE OFF
CREATE TABLE documents ( NAME VARCHAR2(256) NOT NULL, MIME_TYPE VARCHAR2(128) NULL, DOC_SIZE NUMBER NULL, DAD_CHARSET VARCHAR2(128) NULL, LAST_UPDATED DATE NULL, CONTENT_TYPE VARCHAR2(128) NULL, CONTENT LONG RAW NULL, BLOB_CONTENT BLOB ) /
CREATE TABLE documentspart ( DOCUMENT VARCHAR2(256), PART VARCHAR2(256), UPLOADED CHAR(1), constraint documentspart_pk primary key( document, part ) ) /
CREATE OR REPLACE PACKAGE cntsample IS /* This package was written by Audun V. Nes (anes@dk.oracle.com). The intention of this sample is to show the File Upload/Download capabilities of the PL/SQL gateway shipped with iAS. Last updated 24th of May 2000. */ PROCEDURE startup; PROCEDURE menu; PROCEDURE dummy; PROCEDURE upload_form; PROCEDURE upload(name IN owa.vc_arr); PROCEDURE download_form; PROCEDURE download(p_file IN VARCHAR2); PROCEDURE remove_form; PROCEDURE remove(p_file IN owa.vc_arr); END; /
CREATE OR REPLACE PACKAGE BODY cntsample IS
PROCEDURE startup IS BEGIN -- This procedure only creates a simple frameset. htp.htmlOpen; htp.framesetOpen(crows => '72,*'); htp.frame(csrc => 'cntsample.menu', cname => 'frame1', cscrolling => 'NO'); htp.framesetOpen(ccols => '40%,*'); htp.frame(csrc => 'cntsample.dummy', cname => 'frame2', cscrolling => 'NO'); htp.frame(csrc => 'cntsample.dummy', cname => 'frame3', cscrolling => 'AUTO'); htp.framesetClose; htp.framesetClose; htp.htmlClose; EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE menu IS BEGIN -- This procedure creates a simple menu from which the end user can make his choice. htp.htmlOpen; htp.bodyOpen(cattributes => 'TEXT="#FFFFFF" LINK="#FFFFFF" ALINK="#FFFFFF" VLINK="#FFFFFF"'); htp.tableOpen(cattributes => 'BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%" BGCOLOR="#666699"'); htp.tableRowOpen; htp.tableData(htf.img(curl => '/images/wwcban.jpg')); htp.tableData(htf.fontOpen('#FFFFFF', 'arial,helvetica','+2')||'Content Table Sample'||htf.fontClose); htp.tableData(htf.anchor2(curl => 'cntsample.upload_form', ctext => 'Upload File(s)', ctarget => 'frame2')); htp.tableData(htf.anchor2(curl => 'cntsample.download_form', ctext => 'Download File(s)', ctarget => 'frame2')); htp.tableData(htf.anchor2(curl => 'cntsample.remove_form', ctext => 'Remove File(s)', ctarget => 'frame3')); htp.tableData(htf.anchor2(curl => 'owa_util.showsource?cname='||owa_util.get_procedure, ctext => 'View Source Code', ctarget => 'frame3')); htp.tableRowClose; htp.tableClose; htp.bodyClose; htp.htmlClose; EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE dummy IS BEGIN -- This procedure shows an empty page with a background image. It is used in the frameset startup. htp.htmlOpen; htp.bodyOpen(cbackground => '/images/wsd.gif'); htp.bodyClose; htp.htmlClose; EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE upload_form IS BEGIN htp.header(3,'Upload a file'); -- This procedure creates a simple HTML form that lets the end user upload his file(s). htp.formOpen(curl => 'cntsample.upload', cmethod => 'POST', cenctype => 'multipart/form-data'); htp.p(''); htp.formSubmit; htp.formClose; htp.para; htp.header(3,'Upload multiple files'); htp.formOpen(curl => 'cntsample.upload', cmethod => 'POST', cenctype => 'multipart/form-data'); htp.p(''); htp.br; htp.p(''); htp.br; htp.p(''); htp.br; htp.p(''); htp.br; htp.p(''); htp.br; htp.formSubmit; htp.formClose; EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE upload(name IN owa.vc_arr) IS /* This procedure can upload both one single file as well as multiple files. The actual upload is done by the listener. You simply initialize the process by providing the file to be uploaded. */ i BINARY_INTEGER := 0; BEGIN LOOP i := i + 1; IF name(i) IS NOT NULL THEN htp.p(name(i)||' uploaded'); htp.br; ELSE NULL; END IF; END LOOP; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE download_form IS -- This procedure shows you which files can be downloaded, and allows you to do so. CURSOR c1 IS SELECT name FROM documents; BEGIN htp.htmlOpen; htp.bodyOpen; FOR l1 IN c1 LOOP htp.anchor2(curl => 'cntsample.download?p_file='||l1.name, ctext => l1.name, ctarget => 'frame3'); htp.br; END LOOP; htp.bodyClose; htp.htmlClose; EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE download(p_file IN VARCHAR2) IS BEGIN /* The actual download is handled by the PL/SQL gateway based on the settings in your DAD. The code below simply initialize the process by specifying which file to get. */ wpg_docload.download_file(p_file); EXCEPTION WHEN OTHERS THEN htp.p(sqlerrm); RETURN; END;
PROCEDURE remove_form IS -- This procedure creates an HTML form that lets the end user delete unwanted files. CURSOR c1 IS SELECT name, mime_type, doc_size, dad_charset, last_updated, content_type FROM documents; BEGIN htp.header(3,'Select the file(s) to remove'); htp.formOpen(curl => 'cntsample.remove', cmethod => 'POST'); htp.tableOpen(cborder => 'BORDER=1'); FOR l1 IN c1 LOOP htp.tableRowOpen; htp.tableData(htf.formCheckbox(cname => 'p_file', cvalue => l1.name)); htp.tableData(l1.name); htp.tableData(l1.mime_type); htp.tableData(l1.doc_size); htp.tableData(l1.dad_charset); htp.tableData(l1.last_updated); htp.tableData(l1.content_type); htp.tableRowClose; END LOOP; htp.tableClos