8.11. Extended Value Access and File Upload
Interchange has a facility for greater control over the display of form variables; it also can parse multipart/form-data forms for file upload.
File upload is simple. Define a form like:
<FORM ACTION="[process-target] METHOD=POST ENCTYPE="multipart/form-data"> <INPUT TYPE=hidden NAME=mv_todo VALUE=return> <INPUT TYPE=hidden NAME=mv_nextpage VALUE=test> <INPUT TYPE=file NAME=newfile> <INPUT TYPE=submit VALUE="Go!"> </FORM>
The [value-extended ...] tag performs the fetch and storage of the file. If the following is on the test.html page (as specified with mv_nextpage and used with the above form, it will write the file specified:
<PRE> Uploaded file name: [value-extended name=newfile] Is newfile a file? [value-extended name=newfile yes=Yes no=No test=isfile] Write the file. [value-extended name=newfile outfile=junk.upload] Write again with indication: [value-extended name=newfile outfile=junk.upload yes="Written."] no=FAILED] And the file contents: [value-extended name=newfile file_contents=1] </PRE>
The [value-extended] tag also allows access to the array values of stacked variables. Use the following form:
<FORM ACTION="[process-target] METHOD=POST ENCTYPE="multipart/form-data"> <INPUT TYPE=hidden NAME=testvar VALUE="value0"> <INPUT TYPE=hidden NAME=testvar VALUE="value1"> <INPUT TYPE=hidden NAME=testvar VALUE="value2"> <INPUT TYPE=submit VALUE="Go!"> </FORM>
testvar element 0: [value-extended name=testvar index=0] testvar element 1: [value-extended name=testvar index=1] testvar elements: joined with a space: |[value-extended name=testvar]| joined with a newline: |[value-extended joiner="\n" name=testvar index="*"]| first two only: |[value-extended name=testvar index="0..1"]| first and last: |[value-extended name=testvar index="0,2"]|
to observe this in action.
The syntax for [value-extended ...] is:
named: [value-extended name=formfield outfile=filename* ascii=1* yes="Yes"* no="No"* joiner="char|string"* test="isfile|length|defined"* index="N|N..N|*" file_contents=1* elements=1*]
positional: [value-extended name]
Expands into the current value of the customer/form input field named by field. If there are multiple elements of that variable, it will return the value at index; by default all joined together with a space.
If the variable is a file variable coming from a multipart/form-data file upload, then the contents of that upload can be returned to the page or optionally written to the outfile.
The form variable NAME. If no other parameters are present, the value of the variable will be returned. If there are multiple elements, by default they will all be returned joined by a space. If joiner is present, they will be joined by its value.
In the special case of a file upload, the value returned is the name of the file as passed for upload.
The character or string that will join the elements of the array. It will accept string literals such as "\n" or "\r".
There are three tests. isfile returns true if the variable is a file upload. length returns the length. defined returns whether the value has ever been set at all on a form.
The index of the element to return if not all are wanted. This is useful especially for pre-setting multiple search variables. If set to *, it will return all (joined by joiner). If a range, such as 0 .. 2, it will return multiple elements.
Returns the contents of a file upload if set to a non-blank, non-zero value. If the variable is not a file, it returns nothing.
Names a file to write the contents of a file upload to. It will not accept an absolute file name; the name must be relative to the catalog directory. If images or other files are to be written to go to HTML space, use the HTTP server's Alias facilities or make a symbolic link.
To do an auto-ASCII translation before writing the outfile, set the ascii parameter to a non-blank, non-zero value. The default is no translation.
The value that will be returned if a test is true or a file is written successfully. It defaults to 1 for tests and the empty string for uploads.
The value that will be returned if a test is false or a file write fails. It defaults to the empty string.