474,046 Members | 9,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=VBScr ipt %>
<HTML>
<HEAD>
<TITLE>FileUp Upload Simple Sample</TITLE>
</HEAD>
<BODY>
<%
Dim oFileUp
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateOb ject("SoftArtis ans.FileUp")
'--- Set the Path property to the location you wish to temporarily
cache the incoming file before saving
oFileUp.Path = Server.MapPath( "uploads\da ta")
'--- Check if a file was selected (myFile is coming from the html
code)
'--- If so, continue processing
If Not oFileUp.Form("m yFile").IsEmpty Then
'--- Save the file
oFileUp.Form("m yFile").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("m yFile").ServerN ame)
Else
Response.Write( "Error: There was no file submitted for upload.")
End If
'--- Destroy objects
Set oFileUp = Nothing
%>
Webpage Code Upload_File_For m.html

</BODY>
</HTML>
Sample Upload Form (upload_file_fo rm.html)
<HTML>
<HEAD>
<TITLE>FileUp Simple Upload Sample</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=center>&n bsp;</H3>
<H3 ALIGN=center>As p FileUp Upload Sample</H3>
<p ALIGN=center>&n bsp;</p>
<FORM ACTION="fileUp. asp" ENCTYPE="MULTIP ART/FORM-DATA"
METHOD="POST">
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">En ter Filename:</TD>
<!--
Note: Notice this form element is of TYPE="FILE"
-->
<TD ALIGN="LEFT"><I NPUT 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"><I NPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Jul 22 '05 #1
1 10226
Well I guess I answered myself :)

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

Rod
http://www.thelazyadmin.com
"lazyadmin" <ad***@lazyadmi n.com.nospam> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l...
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=VBScr ipt %>
<HTML>
<HEAD>
<TITLE>FileUp Upload Simple Sample</TITLE>
</HEAD>
<BODY>
<%
Dim oFileUp
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateOb ject("SoftArtis ans.FileUp")
'--- Set the Path property to the location you wish to temporarily
cache the incoming file before saving
oFileUp.Path = Server.MapPath( "uploads\da ta")
'--- Check if a file was selected (myFile is coming from the html
code)
'--- If so, continue processing
If Not oFileUp.Form("m yFile").IsEmpty Then
'--- Save the file
oFileUp.Form("m yFile").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("m yFile").ServerN ame)
Else
Response.Write( "Error: There was no file submitted for upload.")
End If
'--- Destroy objects
Set oFileUp = Nothing
%>
Webpage Code Upload_File_For m.html

</BODY>
</HTML>
Sample Upload Form (upload_file_fo rm.html)
<HTML>
<HEAD>
<TITLE>FileUp Simple Upload Sample</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=center>&n bsp;</H3>
<H3 ALIGN=center>As p FileUp Upload Sample</H3>
<p ALIGN=center>&n bsp;</p>
<FORM ACTION="fileUp. asp" ENCTYPE="MULTIP ART/FORM-DATA"
METHOD="POST">
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">En ter Filename:</TD>
<!--
Note: Notice this form element is of TYPE="FILE"
-->
<TD ALIGN="LEFT"><I NPUT 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"><I NPUT 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
6473
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 size limit of 20MB in php.ini. My questions are: 1) If some evil web terrorist tries to upload a file which is larger than the maximum allowed by the setting in php.ini - will the transfer be cancelled by the server when the limit is reached so...
5
5487
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. I want to develop a webpage where people can send attachments that are stored on their local PC.
2
1517
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? Cheers
5
2861
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. tbFileUpload.Accept = "gif,bmp"; Any suggestions?
3
13156
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 ³ and isn¹t checking the file size or preventing the upload. ERROR IS <<<<Œthis.form.uploadfile.value² is null or not an object on this line:
5
3751
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 works at all! if ($_FILES !="") { if ($_FILES<=0) { header("Location: /fileerror.php"); exit; }
10
2578
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 that are not working. Could somebody help me out please. <?php ;
6
1943
by: | last post by:
Hi, I use upload control, how to enable upload *.pdf file and enlarge file size? Please help.
1
47569
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
10339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11604
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12032
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11145
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6655
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6837
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4945
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.