Hi All,
I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before submitting Submit orelse it will give you an error. Thanks in advance for your help.
db-file-to-disk.asp -
<%
-
'Sample file Field-SaveAs.asp
-
'Store extra upload info to a database
-
' and file contents to the disk
-
Server.ScriptTimeout = 5000
-
-
'Create upload form
-
'Using Huge-ASP file upload
-
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
-
'Using Pure-ASP file upload
-
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%
-
-
-
Server.ScriptTimeout = 1000
-
Form.SizeLimit = &HA00000'10MB
-
-
'was the Form successfully received?
-
Const fsCompletted = 0
-
-
If Form.State = fsCompletted Then 'Completted
-
-
'Create destination path+filename for the source file.
-
Dim DestinationPath, DestinationFileName
-
DestinationPath = Server.mapPath("UploadFolder")
-
DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
-
-
-
'Open recordset to store uploaded data
-
Dim RS: Set RS = OpenUploadRS
-
-
'Store extra info about upload to database
-
RS.AddNew
-
RS("UploadDT") = Now()
-
RS("Description") = Form.Texts.Item("Description")
-
RS("SourceFileName") = Form("SourceFile").FilePath
-
RS("DestFileName") = DestinationFileName
-
RS("DataSize") = Form("SourceFile").Length
-
'...
-
RS.Update
-
-
Response.write "<br>Source file names:"
-
Dim Field: For Each Field in Form.Files.Items
-
Response.write "<br> " & Field.FileName
-
Next
-
'{b}Save file to the destination
-
Form("SourceFile").SaveAs DestinationFileName
-
'{/b}
-
-
response.write "<Font color=green><br>SourceFile was saved as " & DestinationFileName
-
response.write "<br>See ListFiles table in " & Server.MapPath("upload.mdb") & " database.</Font>"
-
-
ElseIf Form.State > 10 then
-
Const fsSizeLimit = &HD
-
Select case Form.State
-
case fsSizeLimit: response.write "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
-
case else response.write "<br><Font Color=red>Some form error.</Font><br>"
-
end Select
-
End If'Form.State = 0 then
-
-
Function OpenUploadRS()
-
Dim RS : Set RS = CreateObject("ADODB.Recordset")
-
-
'Open dynamic recordset, table Upload
-
RS.Open "ListFiles", GetConnection, 2, 2
-
-
Set OpenUploadRS = RS
-
end Function
-
-
Function GetConnection()
-
dim Conn: Set Conn = CreateObject("ADODB.Connection")
-
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
-
Conn.open "Data Source=" & Server.MapPath("upload.mdb")
-
set GetConnection = Conn
-
end function
-
-
-
-
%>
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
<HTML><HEAD>
-
<TITLE>ASP huge file upload sample.</TITLE>
-
<STYLE TYPE="text/css"><!--TD {font-family:Arial,Helvetica,sans-serif }TH {font-family:Arial,Helvetica,sans-serif }TABLE {font-size:10pt;font-family:Arial,Helvetica,sans-serif }--></STYLE>
-
</HEAD>
-
<BODY BGColor=white>
-
-
-
<Div style=width:600>
-
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
-
-
<TR>
-
<TH noWrap align=left width="20%" bgColor=khaki> <A
-
href="http://www.pstruh.cz/help/scptutl/upload.asp">Power ASP
-
file upload</A> - upload to disk, store extra file upload info in a database </TH>
-
<TD> </TD></TR></TABLE>
-
<TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
-
-
<TR>
-
<TD colSpan=2>
-
<P> This sample demontrates using
-
of Huge-ASP file upload to upload files to server and store file path in server-side database.
-
The sample ASP file is running with Microsoft.Jet.OLEDB (MDB) connection, but you can use it
-
with any other SQL server or file drivers (MS SQL server, Oracle, MySQL, FoxPro driver, etc.).
-
</P>
-
<P>
-
You can select source file and write some description of the file.
-
Source file is stored on server disk. Description, file name, file size and path to stored file are saved in server-side database along with current upload time.
-
</P>
-
Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB - you can change it, see source) .
-
</TD></TR></TABLE>
-
-
-
-
-
<TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
-
<form method=post ENCTYPE="multipart/form-data">
-
<TR>
-
<TD> </TD>
-
<TD Align=Right><input type="submit" Name="Action" value="Upload the file >>"></TD>
-
</TR>
-
<TR>
-
<TD>File to upload</TD>
-
<TD><input type="file" name="SourceFile"></TD>
-
</TR>
-
<TR>
-
<TD>Description</TD>
-
<TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD>
-
</TR>
-
-
</form></Table>
-
-
-
-
-
<HR COLOR=silver Size=1>
-
<CENTER>
-
<FONT SIZE=1>© 1996 – <%=year(date)%> Antonin Foller, <a href="http://www.pstruh.cz">PSTRUH Software</a>, e-mail <A href="mailto:help@pstruh.cz" >help@pstruh.cz</A>
-
<br>To monitor current running uploads/downloads, see <A Href="http://www.pstruh.cz/help/iistrace/iis-monitor.asp">IISTracer - IIS real-time monitor</A>.
-
</FONT>
-
-
</CENTER>
-
</Div>
-
</BODY></HTML>
2 7649 jhardman 3,406
Recognized Expert Specialist
If it was me, I would add a javascript function called onClick (I would remove the submit button, and use a fake button instead) that checks the input and either submits the form, or posts an alert message.
Jared
BTW, thanks for posting the code, a lot of people have asked for that type of thing.
Hi Jhardman,
Thanks. I got it working. Below is the link to the PURE 10MB ASP Upload Code. It has a bunch of features with upload progress bar .... pretty nice one.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?tx tCodeId=8225&ln gWId=4
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Darren Dale |
last post by:
I love the language. I love the community. My only complaint is that
Python for Windows is built with Visual Studio.
It is too difficult to build python, or a module, from source. This is
what open source is all about, isnt it? I even have a copy of visual
studio, and I still cant build modules from source, because my academic
copy is version 7. As a scientist funded by the NSF, I feel compelled to
do all my work using free software (I...
|
by: Mars |
last post by:
Why this error occurs??
typedef char *string;
int main(void)
{
string str;
str="ajsdklfajsdf";
printf("%s\n",str);
|
by: Michael |
last post by:
How can I determine a users PC Total system memory and memory available or
free at the time of my program loading.
Thanks
|
by: prashantkhoje |
last post by:
hi ppl,
i am developing an C application in Microsoft visual C++ 6.0. i get
following error while running it in debug mode:
/* here's the error message */
program: my_application.exe
DAMAGE: after Block number (#41) at 0x002F51C0
|
by: Stef Mientki |
last post by:
If I create a large array of data or class,
how do I destroy it (when not needed anymore) ?
Assign it to an empty list ?
thanks,
Stef Mientki
| |
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |