You may at times run into situations where you do not want the user to be able to set which files he or she will be uploading. For obvious reasons, this is not allowed with a purely server-based applications, as the security implications would be rather daunting. However, you can preset files with a client-side component.
Using SA-XFile
For this example, you only need to create one file to post to the standard FormResp.asp.
Paste the following code into a standard HTML file:
<HTML>
<BODY>
<SCRIPT LANGUAGE="VBS">
Sub UploadButton_OnClick()
SAXFile.CurrentURL = "http://localhost/saxfilesamples/formresp2.asp"
SAXFile.AddFile "C:\Boot.ini", "FileName1"
SAXFile.Start
ResponseText.InnerHTML = SAXFile.Response
Document.All("UploadButton").Disabled = True
end Sub
</SCRIPT>
<CENTER><H2>IE Based SA-XFile Form Data and Multi-File "Post" Sample</H2>
<BR>
To upload the preset files click the "Upload!" button.
<BR>
<Input Type=Button Name="UploadButton" value="Upload!">
<BR>
</CENTER>
<SPAN ID=ResponseText></SPAN>
<OBJECT CLASSID="ClsID:C3A57B60-C117-11D2-BD9B-00105A0A7E89"
Codebase="saxfile.cab"
ID="SAXFile">
</OBJECT>
</BODY>
</HTML>
The code for this is fairly easy to understand. The object tag at the end creates an instance
of
We named the button in this example 'UploadButton'. Its sole purpose is to fire the sub procedure that proceeds it.
Let's go through the sub procedure line by line:
At this point, you should be able to open the HTML file, press the button, and have the boot.ini from your hard drive uploaded without having selected it manually.
Using SA-JFile
Within SA-JFile, you can script files to be uploaded by using the parameter Filename1.
For multiple files you can increment the last character - Filename2 , Filename3, etc.
Here is an example of one file preset into a Java applet:
<%@ LANGUAGE="VBSCRIPT" %>
<%
' Create a variable to hold the filename to retrieve from the users system
Filename = "c:\boot.ini"
' Get the name of the host machine
httpHost = Request.ServerVariables("HTTP_HOST")
' This is where all the data will be sent
PostURL = "http://" & httpHost & "/SAfileUp3Samples/clientsidesamples/presetfilename/formresp.asp"
%>
<HTML>
<HEAD>
<TITLE>
Software Artisans Java File Upload Simple Sample
</TITLE>
</HEAD>
<BODY>
<center><h2>Software Artisans Java File Upload Simple Sample</h2></center>
The Java Applet contained in this page can point to files which are located on a users local disk.
These default file names can be specified in the Java Applet using applet parameters. The user
can also select files using the Java Applet interface.
<br>
<br>
These files will be submitted to a URL specified as a parameter in the Java applet.
<APPLET CODEBASE="/SAJFileSamples" code="softartisans.filetransfer.UploadClient.class" height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload" VIEWASTEXT>
<PARAM name="cabbase" value="filetransfer.cab">
<!-- The PostURL is where all the files and form elements will be uploaded to -->
<PARAM name="PostURL" value="<%=PostURL%>">
<PARAM name="Filename1" value="<%=FileName%>">
<PARAM name="canRemoveFiles" Value="0">
<!--To enter multiple files simply add them as parameters-->
<!-- config.sys
<param name="Filename2" value="c:\boot.ini">
<param name="Filename3" value="c:\config.sys">
-->
</APPLET>
</BODY>
</HTML>
In this example, we use a server-side script to supply the filename and then passing this into the parameter,Filename1. You could set the filename, by hard coding the path and name.
When the web page is loaded, the applet should show the filename in the file list.
Let go though the key points in the code:
<%
' Create a variable to hold the filename to retrieve from the users system
Filename = "c:\boot.ini"
' Get the name of the host machine
httpHost = Request.ServerVariables("HTTP_HOST")
' This is where all the data will be sent
PostURL = "http://" & httpHost & "/SAfileUp3Samples/clientsidesamples/presetfilename/formresp.asp"
%>
The next key point is the applet tag section. The variables created at the top are now set within the parameters needed.
<APPLET CODEBASE="/SAJFileSamples" code="softartisans.filetransfer.UploadClient.class" height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload" VIEWASTEXT> <PARAM name="cabbase" value="filetransfer.cab"> <!-- The PostURL is where all the files and form elements will be uploaded to --> <PARAM name="PostURL" value="<%=PostURL%>"> <PARAM name="Filename1" value="<%=FileName%>"> <PARAM name="canRemoveFiles" Value="0"> <!--To enter multiple files simply add them as parameters--> <!-- config.sys <param name="Filename2" value="c:\boot.ini"> <param name="Filename3" value="c:\config.sys"> --> </APPLET> </BODY> </HTML>
The filename should show up when the page is loaded. You would then click onto the upload button on the applet.
The web page specified from the PostURL parameter should have an instance of
For more examples, check out the samples provided as part of the
| Previous Page | Next Page |