# File Uploads/Multi-Part Forms

> Source: https://manual.pvxplus.com/apache/multipart

## Uploading Files

The Apache HTTP Interface has built-in logic to parse multi-part form transmissions. This makes the process of having end-users upload files to the host a very simple process.

An upload page typically will consist of an HTML document containing a form with an INPUT field whose type is **"file"**.

***Example:***

|  |  |
| --- | --- |
|  | \<html>  <br>  <br>\<head>  <br>\<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">  <br>\<title>Upload a picture\</title>  <br>\</head>  <br>  <br>\<body>  <br>  <br> \<form action="whatever.pvp" method="post" enctype="multipart/form-data">  <br>  <br> \<p align="center">Enter pathname of the picture to upload:  <br> \<input type="file" size="32" name="flnm" id="filename" accept="image/gif,image/jpg,image/jpeg">  <br> \<br>  <br> \<input type="submit" name="command" value="Upload">  <br> \<input type="submit" name="command" value="Cancel">  <br> \</p>  <br>  <br>\</form>  <br>  <br>\</body>  <br>\</html> |

When this page is received by the Apache HTTP Interface, the variable **FLNM$** will be loaded with the contents of the file submitted by the user. In addition, the fields **FLNM..TYPE$** will contain the file type and **FLNM..FILENAME$** will contain the pathname of the file on the user workstation.

To store the file on the host, simply create a serial file and write the contents of the variable to the file using Binary IO.

***Example:***

```
!
! Sample Web program to store an uploaded file on the host
! in the /tmp directory
!
! The file is received in the FLNM variable
!
     F$=FLNM..FILENAME$
     O=pos("/\":F$,-1)
     F$="/tmp/"+F$(O+1)
     erase F$,err=*next
     serial F$
     open purge (hfn,isz=-1)F$
     write record (lfo)FLNM$
     close (lfo)
     HTML_FILE$="gotfile.htm"
     run "*web/merge"
```
