UploadFiles
Description
Opens the Upload Files dialog box that enables an application
user to upload files from the local computer to the Web server.
Syntax
|
1 |
void <b>UploadFiles</b> (string <i>serverFolder</i>, long <i>bgColor</i>, int <i>fileNum</i>, boolean <i>showServerFolder</i>, string <i>description</i>, string <i>allowExts</i> {, string <i>callbackFunctionName</i>}{, PowerObject <i>po</i> }) |
| Argument | Description |
|---|---|
| serverFolder | The folder on the server to which you want to copy one or more files from the client computer. PowerBuilder creates this folder under the server virtual root in the applicationName_rootsessionsessionID directory, or for someone logged in as a permanent user, in the applicationName_rootusersuserName directory. |
| bgColor | A long for the background color of the Upload Files dialog box. |
| fileNum | An integer for the number of text boxes to display in the Upload Files dialog boxes. Application users can upload as many files as there are text boxes in a single upload operation. |
| showServerFolder | A boolean specifying whether to display the server folder name in the Upload Files dialog box. Values are:
|
| description | Text that you want to display near the top of the Upload Files dialog box. You can use an empty string if you do not want to display additional text in this dialog box. |
| allowExts | A string that lets you limit the files a user can upload to files with the extensions you list. If you set this argument to an empty string, files with any file extension can be uploaded. If you list multiple extensions, you must separate each extension with a semicolon. You must include the “.” (dot) in the extensions you list. |
| callbackFunctionName (optional) | The callback function that lets you know whether the file is correctly uploaded to the Web server. |
| po (optional) |
The name of a PowerBuilder object that has the callback function set in the callbackFunctionName argument. |
Return Values
None.
Usage
You can use the UploadFiles function in
conjunction with a private callback function that you create for
a PowerBuilder object.
The callback function should return an integer and take a
string array for its only argument. The callback function script
should include an iteration to fill up the string array with the
names of files selected by the application user to upload to the
server. For example, the following code can be added to a callback
function “myuploadfiles_callback” with
an upfiles[ ] string array argument:
|
1 |
int i |
|
1 |
for i = 1 to upperbound(up_files) |
|
1 |
this.mle_1.text += "~r~n" + up_files[i] |
|
1 |
next |
|
1 |
return i |
If the “myuploadfiles_callback” function
is created on the window w_main, you can use this window
name as the value of the po argument in your Upload Files call.
If you create the “myuploadfiles_callback” function
as a global function, you can use the UploadFiles callback
syntax without the po argument.
If your application uses sequential UploadFiles calls
in the same script, only the callback function in the last of the UploadFiles calls
is valid. The other UploadFiles calls can still
upload selected files to the Web server, but further processing
of the names of the uploaded files does not occur, even when the syntax
for these calls includes a callback function that codes for such processing.
If the last UploadFiles call in a script
containing sequential UploadFiles calls does
not use a callback function, no callback processing occurs.
Examples
The following example uploads the file to the application’s
virtual root d:hhh directory on the
server, sets the color of the Upload Files dialog box to the background
color of the w_main application window, limits the number
of files to be uploaded in a single operation to 3, does not display
the server directory name in the Upload Files dialog box but does
display the “my description” text, and limits
the types of files that can be uploaded to JPG and TXT files:
|
1 |
#if defined PBWEBFORM then |
|
1 |
UploadFiles("d:hhh", w_main.BackColor, 3, false, <br /> "my description", ".jpg;.txt", <br /> "myuploadfiles_callback", w_main) |
|
1 |
#end if |
This example uses green as the background color for the Upload
Files dialog box, limits the number of files to be uploaded in a
single operation to 1, displays the server folder name in the Upload
Files dialog box, and does not restrict the types of files a user
can upload to the Web server:
|
1 |
#if defined PBWEBFORM then |
|
1 |
UploadFiles("c:hhh", RGB(0, 255, 0), 1, true, "", "", "myuploadfiles_callback", w_main) |
|
1 |
#end if |