Member variable HttpRequest():Files Foundation
Provides access to the files uploaded from the browser.
The member variable :Files provides access to files that have been uploaded from the web browser.
The following HTML markup is required for uploading a file to upload.cxp. The method attribute must be post, the enctype attribute must be multipart/form-data.
<form action="upload.cxp" method="post" enctype="multipart/form-data">
<input type="file" name="filedata" />
<input type="submit" name="SubmitButton" />
</form>
In the following example the member variable :NumItems is used to test if a file was uploaded from the browser. The file then is accessed via a member variable with the name :filedata which is an instance of the class HttpUploadedFile. Note that the name of the instance variable corresponds with the name attribute of the HTML input tag above:
@IF 0 == ::HttpRequest:Files:NumItems
<h1>No file was uploaded</h1>
@ELSE
@oHttpUploadedFile := ::HttpRequest:Files:filedata
<h1>File received</h1>
<h2>The name is @(oHttpUploadedFile:Name)</h2>
@ENDIF
Assumed the file readme.txt was uploaded then this is the resulting HTML markup:
<h1>File received</h1>
<h2>The name is readme.txt</h2>
It is possible to upload more then one file at the same time by having several file input elements in a single form:
<form action="upload.cxp" method="post" enctype="multipart/form-data">
<input type="file" name="filedata1" />
<input type="file" name="filedata2" />
<input type="submit" name="SubmitButton" />
</form>
The :Files object provides the method :getItem() and the instance variable :NumItems that allow to iterate through the HttpUploadedFile instances:
@IF 0 == ::HttpRequest:Files:NumItems
<h1>No file was uploaded</h1>
@ELSE
<h1>Files received</h1>
@FOR nFile := 1 TO ::HttpRequest:Files:NumItems
@oHttpUploadedFile ::HttpRequest:Files:getItem( nFile )
<h2>Name #@(Str(nFile,1)) is @(oHttpUploadedFile:Name)</h2>
@NEXT
@ENDIF
The resulting HTML markup will look like this in case image.png and description.xml have been upload:
<h1>Files received</h1>
<h2>Name #1 is image.png</h2>
<h2>Name #2 is description.xml</h2>
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.