473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP File Upload - Limit File Types?

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>&nbsp;</H3>
<H3 ALIGN=center>Asp FileUp Upload Sample</H3>
<p ALIGN=center>&nbsp;</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">&nbsp;</TD>
<TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Jul 22 '05 #1
1 10177
Well I guess I answered myself :)

http://www.learnasp.com/learn/uploadlimitsize.asp

Rod
http://www.thelazyadmin.com
"lazyadmin" <ad***@lazyadmin.com.nospam> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
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>&nbsp;</H3>
<H3 ALIGN=center>Asp FileUp Upload Sample</H3>
<p ALIGN=center>&nbsp;</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">&nbsp;</TD>
<TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Thomas Mlynarczyk | last post by:
Hello, I want to upload files via an HTML form and store them somewhere on my webspace. So far so good. I am just a bit concerned about security issues and traffic. My provider has set a file...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
2
by: dhnriverside | last post by:
Hi I'm trying to restrict file types with a HtmlInputFile Accept property. It seems that this isn't supported for IE6? (doh!). Can anyone recommend any free Upload components? Or a solution? ...
5
by: Jon Natwick | last post by:
I would like to limit the file types that users can upload. <input id="tbFileUpload" type="file" runat="server"> This setting looks like it should it work, but it's not working for me. ...
3
by: Jefferis NoSpamme | last post by:
Hello all, I'm trying to limit the file size to 1 meg on upload of image files and I am trying a script from javascript internet, but it is giving me errors on IE ² is null or not an object ³...
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
10
by: jonathan184 | last post by:
Hi I am tryin to validate certian types of files to be uploaded and file size and if this follows this correctly then insert in db this is the code i did so far. So far I commented out the parts...
6
by: | last post by:
Hi, I use upload control, how to enable upload *.pdf file and enlarge file size? Please help.
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.