Related Topics . . Home


Uploading Client Files

If you use a Web browser that supports client file upload (using the ENCTYPE attribute of the FORM tag), you can use Universal Web Connect to upload files from your client machine.

The following is an example HTML form that retrieves an image file into the input_image1 variable and is processed by the process_file AppPage:

  <FORM ENCTYPE=multipart/form-data METHOD=POST> ACTION=<?MIVAR>$WEB_HOME<?/MIVAR>>
  <INPUT TYPE=TEXT NAME=file_name>
  <INPUT TYPE=FILE NAME=input_image1>
  <INPUT TYPE=SUBMIT VALUE="Send File">
  <INPUT TYPE=HIDDEN NAME=MIval VALUE=process_file>
  </FORM>

Set the following wcconfig.std file variable to upload client files.

Variable

Mandatory?

Content

MI_WEBUPLOADDIR No Directory on the Web server machine in which uploaded files are placed. Default is your default temporary directory.

In the preceding example, if MI_WEBUPLOADDIR is set to C:\local\Web\uploads, the file C:\local\Web\uploads\input_image1.PID (where PID is the process ID) is created when the form is submitted. If MI_WEBUPLOADDIR is not set, the uploaded files are placed in your default temporary directory. After processing is complete, the uploaded file is removed from the MI_WEBUPLOADDIR directory.

When the form is submitted, you can access the following variables in the AppPage that processes the form.

Variable Name

Description

input_file Full pathname of the uploaded file on the Web server machine.
input_file_name Full pathname of the client file.
input_file_type MIME type of the uploaded file (may be unknown).

In the preceding example, if the client file is named D:\images\input_image.gif, the following variables are accessible in the process_file AppPage.

Variable Name

Assignment

input_image1 C:\local\Web\uploads\input_image1.PID
input_image1_name D:\images\input_image.gif
input_image1_type image/gif

If Universal Web Connect is unable to write the file to the directory specified by MI_WEBUPLOADDIR, the value of the file variable is set to ERR_FOPEN.

The following example illustrates the use of client file upload where uploaded files are stored in the uploads table with the schema:

  CREATE TABLE uploads
  (
  name varchar(40),
  object_type varchar(40),
  object byte,
  local_file varchar(100));

When the object is inserted into the database, initially the row is added to the webImages table with a null value for the object. Then the UpdateBlob event, provided by Universal Web Connect, creates a large object from the uploaded image. The following is the upload_file AppPage:

  <HTML>
  <HEAD><TITLE>File Upload Form</TITLE></HEAD>
  <BODY>
  <HR>
  <FORM ENCTYPE=multipart/form-data METHOD=POST ACTION=<?MIVAR>$WEB_HOME<?/MIVAR>>
  <INPUT TYPE=HIDDEN NAME=MIval VALUE=upload_file>
  <INPUT TYPE=HIDDEN NAME=action VALUE=on>
  <TABLE>
  <TR><TD>Name: </TD><TD><INPUT NAME=ID SIZE=40 TYPE=TEXT>
  </TD></TR>
  <TR><TD>File: </TD><TD><INPUT NAME=object SIZE=40 TYPE=FILE>
  </TD></TR>
  </TABLE>
  <HR>
  <INPUT TYPE=SUBMIT VALUE="Insert New Object">
  </FORM>
  <?MIBLOCK COND=$(XST,$action)>
	  <HR>
	  <?MIVAR NAME=sql_statement>
	    INSERT into uploads VALUES ('$ID', '$object_type', NULL,'$object_name');
	  <?/MIVAR>
	  <?MISQL SQL="$sql_statement">
	    Inserted $MI_ROWCOUNT new objects.<P><?/MISQL>
     <?MIEVENT NAME=UpdateBlob MItab=uploads MInam=name LOADFILE=Y>
	  <?MIVAR>The SQL executed was <I>$sql_statement</I>.<P><?/MIVAR>
  <?/MIBLOCK>
  <B> Here are all of the uploaded objects:</B>
  <TABLE>
  <?MISQL SQL="select name, object_type, local_file from uploads;">
  <TR><TD><A HREF="$WEB_HOME?MIvalObj=$1&MItypeObj=$2&MItabObj=uploads&MInamObj=name">$1</A>
  </TD><TD>$3</TD></TR>
  <?/MISQL>
  </TABLE>
  </BODY>
  </HTML>

The following is sample Web browser output.

Related Topics

Using Variables and Variable Expressions in AppPages


Top of Page . . Home