L
lazyadmin
I would like to use this code on my website to allow simple file uploads
from clients. I would like to restrict the file types they can upload.
Can this be done? Any help appreciated.
Rod
http://www.thelazyadmin.com
ASP Code upload_file.asp
<% @Language=VBScript %>
<HTML>
<HEAD>
<TITLE>FileUp Upload Simple Sample</TITLE>
</HEAD>
<BODY>
<%
Dim oFileUp
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
'--- Set the Path property to the location you wish to temporarily
cache the incoming file before saving
oFileUp.Path = Server.MapPath("uploads\data")
'--- Check if a file was selected (myFile is coming from the html
code)
'--- If so, continue processing
If Not oFileUp.Form("myFile").IsEmpty Then
'--- Save the file
oFileUp.Form("myFile").Save
'--- The file is saved, display a confirmation message
Response.Write ("<B>File saved successfully on the server
as:</B><BR>")
'--- The ServerName() property is the full path of the file where it
was saved on the server
Response.Write(oFileUp.Form("myFile").ServerName)
Else
Response.Write("Error: There was no file submitted for upload.")
End If
'--- Destroy objects
Set oFileUp = Nothing
%>
Webpage Code Upload_File_Form.html
</BODY>
</HTML>
Sample Upload Form (upload_file_form.html)
<HTML>
<HEAD>
<TITLE>FileUp Simple Upload Sample</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=center> </H3>
<H3 ALIGN=center>Asp FileUp Upload Sample</H3>
<p ALIGN=center> </p>
<FORM ACTION="fileUp.asp" ENCTYPE="MULTIPART/FORM-DATA"
METHOD="POST">
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>
<!--
Note: Notice this form element is of TYPE="FILE"
-->
<TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile" size="20"><BR>
Please click Browse to select a file.</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"> </TD>
<TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
from clients. I would like to restrict the file types they can upload.
Can this be done? Any help appreciated.
Rod
http://www.thelazyadmin.com
ASP Code upload_file.asp
<% @Language=VBScript %>
<HTML>
<HEAD>
<TITLE>FileUp Upload Simple Sample</TITLE>
</HEAD>
<BODY>
<%
Dim oFileUp
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
'--- Set the Path property to the location you wish to temporarily
cache the incoming file before saving
oFileUp.Path = Server.MapPath("uploads\data")
'--- Check if a file was selected (myFile is coming from the html
code)
'--- If so, continue processing
If Not oFileUp.Form("myFile").IsEmpty Then
'--- Save the file
oFileUp.Form("myFile").Save
'--- The file is saved, display a confirmation message
Response.Write ("<B>File saved successfully on the server
as:</B><BR>")
'--- The ServerName() property is the full path of the file where it
was saved on the server
Response.Write(oFileUp.Form("myFile").ServerName)
Else
Response.Write("Error: There was no file submitted for upload.")
End If
'--- Destroy objects
Set oFileUp = Nothing
%>
Webpage Code Upload_File_Form.html
</BODY>
</HTML>
Sample Upload Form (upload_file_form.html)
<HTML>
<HEAD>
<TITLE>FileUp Simple Upload Sample</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=center> </H3>
<H3 ALIGN=center>Asp FileUp Upload Sample</H3>
<p ALIGN=center> </p>
<FORM ACTION="fileUp.asp" ENCTYPE="MULTIPART/FORM-DATA"
METHOD="POST">
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>
<!--
Note: Notice this form element is of TYPE="FILE"
-->
<TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile" size="20"><BR>
Please click Browse to select a file.</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"> </TD>
<TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>