Advanced upload example
This example adds the record to "Titles" table including
a reference to uploaded cover page image. Here is the code for page containing the form:
<!--
[FormFields]
WB_Command=R
-->
<!--WB_BeginTemplate-->
<html>
<head>
<title>Add
Titles</title>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta http-equiv="Content-Language"
content="en-us">
</head>
<body>
<form
action="titlesAdd.wbsp" method="POST" align="center" id="addForm"
ENCTYPE="multipart/form-data">
<table border="0" cellpadding="0"
cellspacing="0">
<tr>
<td>Title</td>
<td
align="right"><input type="text" name="WBF_Title" value
size="20"></td>
</tr>
<tr>
<td>Year
Published </td>
<td align="right"><input type="text"
name="WBF_Year Published" value
size="20"></td>
</tr>
<tr>
<td>ISBN</td>
<td
align="right"><input type="text" name="WBF_ISBN" value
size="20"></td>
</tr>
<tr>
<td>Publisher
</td>
<td align="right"><select name="WBF_PubID"
size="1">$wbsr[selpublisher.sr]</select></td>
</tr>
<tr>
<td>Author</td>
<td
align="right"><select name="WBF_AU_ID"
size="1">$wbsr[selauthor.sr]</select></td>
</tr>
<tr>
<td>Book
cover (image)</td>
<td align="right"><input type="file"
name="WBF_imageURL"
size="20"></td>
</tr>
<tr>
<td> </td>
<td
align="right"><input type="submit" name="sButt" value="Add new
title"></td>
</tr>
</table>
</form>
</body>
</html>
and
titlesAdd.wbsp file should look something like this:
[FormFields]
WB_BaseName=biblioA.mdb
WB_AllowMultipart=T
WB_Command=A
WB_Redirect=$wbe[http_referer]$wbif[$wbindof[$wbe[http_referer]|?]>0||?wb_startrec=$wbv[sr]]
WB_RcdSet=Titles
[Upload]
WB_Disallow=![jpg,gif]
WB_UploadDir=/images/
WB_BaseURL=/images/
WB_Overwrite=F
WB_MaxFSize=24576
WB_UploadLog=upload.log
In this example, when visitor enters the values in all form fields (including
the image file to be uploaded using WBF_ImageUrl) and submits the form, WBSP
will accept the data and:
- Check the Upload variable for current virtual host in wbsp.ssc file
- If uploading is enabled WBSP engine will read the WB_AllowMultipart
variable from WBSP file titlesAdd.wbsp
- Since it exists and is set to True WBSP engine will process the uploaded
file (e.g. mycover.gif)
- First WBSP checks if the file size is less then or equal to the number
specified in variable WB_MaxFSize (24576 bytes
in this example)
- If file size is OK, WBSP saves the file in directory specified in variable
WB_UploadDir (directory images in servers
document root)
- If file with same name already exists it will generate unique file name
(because WB_Overwrite is set to False) for
uploaded file
- Next WBSP changes the value of form variable WBF_ImageURL to WB_BaseURL+name of the saved file (in this example
/images/mycover.gif)
- WBSP writes the log record in log file specified in variable WB_UploadLog (in this example file upload.log
located in same dir with file titlesAdd.wbsp)
- After this WBSP engine will continue processing the WBSP file to complete
the Add record command (specified by WB_Command=A) as it was ordinary form,
with the exception of the value of table field imageurl which
will have value /images/mycover.gif
(relative URL of the uploaded file, and not the file itself).