Uploading files from web forms

Advanced topics

1. HTML form requirements
2. Handle the data received in your script.


All browsers worth their salt now support file uploading.
In order to support this in your applications, you need to make sure you do the following:
1. Ensure the required fields are present in your HTML form.
2. Handle the data received in your script.

1. HTML form requirements.
Here's what your form tag should look like:

    <FORM action="/url/to/aptilis.exe" method="POST" ENCTYPE="multipart/form-data">
    <INPUT type="hidden" name="file" value="/path/to/your/aptilis/script.e.txt">
    ...
    </FORM>
Note in particular the ENCTYPE attribute set to "multipart/form-data". This tells the browser to send the data in a slightly different way than usual, to cater for possibly bigger, non-text, data chunks.

Now inside this form, you need to offer the user the capability to specify a file (or more) to upload:

    <INPUT type="file" name="parcel">
Did you know this Input type? Well it's required for file uploads. On the HTML page it will look like a text box, with a browse button attached to it - unfortunately for designers, this button cannot be replaced by a graphic.
Example:

2. Handle the data received in your script.
Now, as you would expect from a normal Aptilis script, you will get the entire uploaded file data in the variable 'parcel' - as per our example above. Of course you can name this variable whatever you want.
Now, in addition no normal Aptilis handling of web form fields, 'parcel' is actually an array. (And with Aptilis 'parcel' is the same as 'parcel[0]').
And in 'parcel[1]', you get the filename of the file sent to you. Of course the filename could be important for you to have if the file uploaded is destined to be copied in a repository.

Code example:

    filename = parcel[1] $