Upload - File transfers from the Web client to the server
The
PmaWebDir object allows to provide a HTML page with a form that allows the client to select file(s) located on the Web client computer and send them to the server.
Page template (upload.htm):
<html>
<head>
<title>Upload file</title>
<style type="text/css">
body {background-color:#efefef;}
hr,div {width:400px;}
h2 {color:#000080;text-align:center;}
</style></head>
<body><div>
<h2>Select a file to upload to the server</h2>
<form enctype="multipart/form-data" method="post" action="#">
File to upload: <input id="fileupload" name="myfile" type="file" multiple/><hr/>
<input type="submit" id="submit" value="Upload to server"/>
</form>
</div></body>
</html>
The page can also be created in the script in the
onPageModify event if the "
Data source" configurator is set to
Text set into the pEvent.PageString property in the onPageModify event. Such approach is used in the preconfiguration
Preconfiguration "PmaWebDir - Uploading files from Web client to the server".
Processing:
The processing of received files and saving into the folder
#data: is executed in the
onPageAction event as follows:
JavaScriptVBScriptSelect and copy to clipboard
var oData = pEvent.Data;
if (Pm.GetVarType(oData, 1) == "PmBuffer")
{
var aParts = Pm.HttpFormDataParse(oData);
var iParts;
for (iParts = 0; iParts < oData.GetSize(1); iParts++)
{
var mPart = aParts.GetItem(iParts, -1);
mPart.Value.SaveToFile(0, "#data:" + mPart.File, 0, -1);
}
}
Dim oData
Set oData = pEvent.Data
If Pm.GetVarType(oData, 1) = "PmBuffer" Then
Dim aParts, iParts
aParts = Pm.HttpFormDataParse(oData)
For iParts = 0 To oData.GetSize(1) - 1
Dim mPart
Set mPart = aParts.GetItem(iParts, -1)
mPart.Value.SaveToFile 0, "#data:" & mPart.File, 0, -1
Next
End If
Opening the page:
Script in the
onButtonUp event of the
PmgButton object that opens the
upload.htm page of the
PmaWebDir object that can be used for sending the file to the server.
JavaScriptSelect and copy to clipboard
var oCreator = Pm.CreateView(null, "/Web/Dir", "file:upload.htm", "target:_blank;");
oCreator.Open();