JFile allows the user to upload one or more individual files, or a whole directory.
JFile's addDirectory method adds the contents of a directory, excluding sub-directories, to the
upload. addDirectoryRecursive uploads a directory with its subdirectories, maintaining the original directory
structure. When uploading a directory, use SoftArtisans FileUp's
SaveRecursive method in your response script, as demonstrated in Exercise 4.To upload a directory recursively, check Recursive. Using the system's native file selection dialog, you cannot browse to a folder and click "Open" to add it to the file/folder list. Instead, enter the directory path and name in the File/Dir input field. To allow the user to browse to a folder and select it, set JFile's UseNativeFileSelection parameter to 0. When UseNativeFileSelection is disabled, JFile will display a platform-neutral file selector when the user clicks Add Files/Directory.
|
|
upl.Form(item).SaveAs filename
with upl.SaveRecursive()
.
"X:\\FolderName\\SubFolderName"
with a valid directory path. Name the script RecursJFile.htm and save it in your JFileScripts
directory.
<!-- The script's onload event calls the function myTransferProgress(), defined below. -->
<BODY language="javascript" onload="myTransferProgress()">
<APPLET codebase="/JFileScripts" code="softartisans.filetransfer.UploadClient.class"
height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload">
<!-- The Cabbase parameter specifies the cab file containing the applet. -->
<PARAM name="cabbase" value="filetransfer.cab">
<!-- The PostURL parameter specifies the URL to which the file will be posted. -->
<PARAM name="PostURL" value="http://localhost/jfilescripts/RecursJFileResp.asp">
</APPLET>
<SCRIPT language="Javascript">
// JFile will set the variable SAJFileAppletLoaded to True when the applet is loaded.
var SAJFileAppletLoaded = False;
// The function myTransferProgress() adds a directory to the applet's upload list.
function myTransferProgress()
{
if(SAJFileAppletLoaded)
{
// addDirectoryRecursive adds the specified directory to the list of files and folders to
// upload. Enter a valid directory and path.
document.fileupload.addDirectoryRecursive("X:\\FolderName\\SubFolderName")
}
else
alert("Applet is not loaded.");
}
</SCRIPT>
</BODY>
BODY
tag's onload
attribute is set to "myTransferProgress()"
, that is, when loaded,
the script will call the myTransferProgress()
function.APPLET
tag adds JFile's UploadClient applet to your web page. We assigned values to several APPLET
attributes:Codebase
Codebase
is optional. When the Java class is in a different
directory, specify the complete relative path or URL.Code
Height
and Width
<PARAM name="UseAppletInBrowser" value=1>
If you do not set UseAppletInBrowser to 1, that is, if you display the applet in a separate window, set
Height
and Width
to 0.Mayscript
Archive
Name
Name
. Use the
name you assign to reference the UploadClient applet in script.Cabbase
parameter specifies the cab file containing the Java applet. Filetransfer.cab contains JFile's Java
class files for Microsoft VM.PostURL
parameter specifies the URL to which the file will be posted, http://localhost/jfilescripts/RecursJFileResp.asp.
RecursJFileResp.asp uses SoftArtisans FileUp to process the upload.myTransferProgress()
is called by the script's onload
event. If the variable
SAJFileAppletLoaded
is True, that is, if the applet loaded successfully, myTransferProgress()
will preset
a specified folder for upload, using the method addDirectoryRecursive
. addDirectoryRecursive
uploads
a directory with its subdirectories, maintaining the original directory structure. JavaScript methods are case-sensitive. |
Copyright © 2000-2003 SoftArtisans, Inc. All rights reserved.