Uploading file

This is a discussion on "Uploading file" within the Classic ASP section. This forum, and the thread "Uploading file are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 15th, 2005, 04:56
New Member
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Uploading file

with the files below, i can upload file to my web server, but the problem occurs when i add another form so that i can upload 2 files together. i cant seem to upload them both together. i get an error bout the key existing. what i want to know is what do i have to add in the codes so that i can upload 2 files.
thanks
Code: Select all
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%option explicit%>
<%Response.Buffer = True%>
<!--#include file="../../includes/AccessChecking.asp" -->
<!--#include file="include/top.asp" -->
<html>
<head>
<title>Engineer Record</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include file="../../includes/date.js" -->
<!--#include file="../../includes/general.asp" -->
<!--#include file="validateFormData/ernogenerate.asp" -->
<link href="../../styles/vrformstyle.css" rel="stylesheet" type="text/css">
<link href="../../styles/navibarstyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
function CheckForm()
{
var formName = document.frEngReport
if (formName.title.value.length <= 0)
{
alert("Please fill in the Title.")
return false
}
return true	
}
</script>
</head>
<%
Session("ERecordBegin") = True
%>
<body>
<%
dim dtYear
dtYear = request.QueryString
%>
<body>
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="66%" height="40"><h1>Engineer Record </h1></td>
<td width="34%"><div align="right">
<h6>Today's Date: <%=DateTodayLong%></h6>
</div></td>
</tr>
</table>
<div align="center">
<table class="tbbackground" width="100%" border="1" cellpadding="2" cellspacing="1" bordercolor="#FFFFFF">
<tr>
<td width="34%"><div align="center"><font size="4">Add  Record</font></div></td>
<td width="28%" bgcolor="#000080"><div align="center"><font size="4"><a class="menulink" href="ereditlist.asp">Edit Records</a></font></div></td>
<td width="38%" bgcolor="#000080"><div align="center"><font size="4"><a class="menulink" href="erlist.asp">View/Validate Records</a></font></div></td>
</tr>
</table>
<table width="100%" bgcolor="#99CCFF">
</table></div>
<form class="formbgcolor" action="validateFormData/ervalidate.asp" method="post" enctype="multipart/form-data" name="frEngReport" id="frEngReport">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> 
<td width="14%" height="47"><img name="logo" src="../../sources/pics/logo1.gif" width="110" height="30" alt=""></td>
<td width="66%" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td><div align="center"> 
<h3><strong>MONTHLY REPORT - 
<%= UCase(MonthName(Month(Now))) %>&nbsp; <%=UCase(Year(Now)) %> </strong></h3>
</div></td>
</tr>
<tr> 
<td><div align="center">MATERIAL CHARACTERIZATION 
DEPARTMENT</div></td>
</tr>
</table></td>
<td width="20%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td><div align="right"><font size="-1">Format 
No: <%=engineerFormatNo%></font></div></td>
</tr>
<tr> 
<td><div align="right"><font size="-1">Effect. 
Date: <%=engineerEffectDate%></font></div></td>
</tr>
</table></td>
</tr>
<tr> 
<td colspan="4">&nbsp;</td>
</tr>
<tr> 
<td colspan="2">DATE OF REPORT: <font color="#0000FF"><%=UCase(DateTodayLong)%></font></td>
<td colspan="2"><div align="right">REPORT NO: <font color="#0000FF"><%=strReportID%></font></div></td>
</tr>
<tr> 
<td height="282" colspan="4">
<table width="787" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000" height="129">
<!-- MSTableType="layout" -->
<tr>
<td width="487" rowspan="3" valign="top">
<table border="0" width="487" id="table1" height="121">
<tr>
<td width="65" height="20"><b>
<font size="4">TITLE:</font></b></td>
<td width="412" rowspan="2">
<textarea rows="6" name="title" cols="44" id="title"></textarea></td>
</tr>
<tr>
<td width="65">&nbsp;</td>
</tr>
</table>
</td>
<td valign="top">&nbsp;Prepared 
by:</td>
<td height="34" valign="top">&nbsp;Checked 
by:</td>
</tr>
<tr>
<td>&nbsp;<%=Ucase(Request.Cookies("USER")("LoginName"))%></td>
<td height="46">&nbsp;</td>
</tr>
<tr>
<td width="146">&nbsp;<%=UCase(DateTodayShort)%></td>
<td width="144" height="45">&nbsp;</td>
</tr>
</table>
<br />
<table width="100%" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr> 
<td><p><strong>Introduction :</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><p>&nbsp;<textarea rows="12" name="introduction" cols="94" id="introduction"></textarea></p></td>
<td width="4">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table width="100%" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td><strong>Experimental :</strong><p>&nbsp;<textarea rows="12" name="experimental" cols="94" id="experimental"></textarea></td>
</tr>
</table>
<br />
<table width="100%" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td><p><strong>Results and discussion :</strong></p>
<p>&nbsp;<textarea rows="12" name="results" cols="94" id="results"></textarea></p>
</td>
</tr>
</table>
<br />
<table width="100%" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr> 
<td><p><strong>Conclusion :</strong></p>
<p>
&nbsp;<textarea name="conclusion" cols="94" rows="12" id="conclusion"></textarea>&nbsp;
</p></td>
</tr>
</table>
<p> 
<p><b>Select a file to upload (if any):</b><br>
<INPUT TYPE=FILE SIZE=70 NAME="FILE1">
<input name="hdSaveTo" type="hidden" id="hdSaveTo" value="disk">
<INPUT TYPE=FILE SIZE=70 NAME="FILE1">
<input name="hdSaveTo" type="hidden" id="hdSaveTo" value="disk">
&nbsp;<p>
&nbsp;<p>
</p>
</p>
<p> 
<input name="btnSubmit" type="submit" id="btnSubmit" value="Submit" onClick="return CheckForm()">
<input name="btnReset" type="reset" id="btnReset" value="Reset">
<input name="hdstrReportID" type="hidden" id="hdstrReportID" value="<%=strReportID%>">
</p>
</td>
</tr>
</table>
</form>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 15th, 2005, 04:57
New Member
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Uploading file

this is the second file

Code: Select all
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit %>
<%Response.Buffer = True%>
<html>
<head>
<title>Engineer Report Validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include file="upload.asp" -->
<!--#include file="../../../includes/general.asp" -->
<link href="../../../styles/navibarstyle.css" rel="stylesheet" type="text/css">
</head>
<%
if not Request.Cookies("USER")("Valid") then 
Response.Redirect(urlLoginPageShort)
end if
if not Request.Cookies("USER")("Reporting") then
Response.Redirect(urlDeniedShort)
end if
if Session("ERecordBegin") then
else
Response.Write(strRecordAddedAlready)
Response.End()
end if
%>
<body>
<%
Dim strReportID, conn
Dim sqlReportID, sqlBreakdownReport
Dim dtDate, dtTime,dtDateOp, dtTimeOp
' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader
' This starts the upload process
Uploader.Upload()
'******************************************
' Use [FileUploader object].Form to access 
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************
strReportID = Uploader.Form("hdstrReportID")
'===IF no instructions are filled in===
if IsNull(Uploader.Form("txtOthers")) then
Response.Write("You must fill in the instructions")
Response.End()
end if
If Uploader.Files.Count = 0 Then	
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("..\..\..\sources\db\engineerreport.mdb")
sqlReportID = ""
sqlReportID = "INSERT INTO recordtable ([ReportID], [Date of Report], [Title], [Introduction], " _
& "[Experimental], [Results], [Conclusion], " _
& "[Prepared By]) VALUES ("  _
& "'" & strReportID & "',#" & DateTodayShort & "#,'" & Uploader.Form("title") & "','" & Uploader.Form("introduction") & "'," _
& "'" & Uploader.Form("experimental") & "','"& Uploader.Form("results") & "','" & Uploader.Form("conclusion") & "',"  _
& "'" & Request.Cookies("USER")("LoginName") & "')"
conn.Execute sqlReportID
Else
' Loop through the uploaded files
For Each File In Uploader.Files.Items
' Check where the user wants to save the file
If Uploader.Form("hdSaveTo") = "disk" Then
' Save the file
File.SaveToDisk "C:\INETPUB\wwwroot\MCDOnlineSystem\DepartmentReport\EngineerReport2\Uploadfiles\"
ElseIf Uploader.Form("saveto") = "database" Then
' Open the table you are saving the file to
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
RS.AddNew ' create a new record
RS("filename")    = File.FileName
RS("filesize")	  = File.FileSize
RS("contenttype") = File.ContentType
' Save the file to the database
File.SaveToDatabase RS("filedata")
' Commit the changes and close
RS.Update
RS.Close
End If
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("..\..\..\sources\db\engineerreport.mdb")	
sqlReportID = ""
sqlReportID = "INSERT INTO recordtable ([ReportID], [Date of Report], [Title], [Introduction], " _
& "[Experimental], [Results], [Conclusion], " _
& "[Prepared By], [Uploaded File]) VALUES ("  _
& "'" & strReportID & "',#" & DateTodayShort & "#,'" & Uploader.Form("title") & "','" & Uploader.Form("introduction") & "'," _
& "'" & Uploader.Form("experimental") & "','"& Uploader.Form("results") & "','" & Uploader.Form("conclusion") & "',"  _
& "'" & Request.Cookies("USER")("LoginName") & "','" & File.FileName & "')"
conn.Execute sqlReportID
Next
End If
if err <> 0 then
Response.Write("<h1>No update permissions!</h1>" & "<br />")
Response.Write(err.Description & "<br />")
Response.Write(err.Source & "<br />")
Response.Write(err.SQLState & "<br />")
Response.End()
end if
conn.close
set conn = nothing
Session("ERecordBegin") = False
Response.Write(strRecordAdded)
%>
<!-- Javascript Redirection --->
<script type="text/javascript">
var timer = null
timer = setTimeout("redirect()",2000)
function redirect()
{
window.location="../reportmain.asp"
}
</script>
<!--End of JavaScript Redirection --->
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 15th, 2005, 04:58
New Member
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Uploading file

i am using the pure asp upload by Jacob

Code: Select all
<%
'***************************************
' File:	  Upload.asp
' Author: Jacob "Beezle" Gilley
' Email:  avis7@airmail.net
' Date:   12/07/2000
' Comments: The code for the Upload, CByteString, 
'			CWideString	subroutines was originally 
'			written by Philippe Collignon...or so 
'			he claims. Also, I am not responsible
'			for any ill effects this script may
'			cause and provide this script "AS IS".
'			Enjoy!
'****************************************

Class FileUploader
	Public  Files
	Private mcolFormElem

	Private Sub Class_Initialize()
		Set Files = Server.CreateObject("Scripting.Dictionary")
		Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
	End Sub
	
	Private Sub Class_Terminate()
		If IsObject(Files) Then
			Files.RemoveAll()
			Set Files = Nothing
		End If
		If IsObject(mcolFormElem) Then
			mcolFormElem.RemoveAll()
			Set mcolFormElem = Nothing
		End If
	End Sub

	Public Property Get Form(sIndex)
		Form = ""
		If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
	End Property

	Public Default Sub Upload()
		Dim biData, sInputName
		Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
		Dim nPosFile, nPosBound

		biData = Request.BinaryRead(Request.TotalBytes)
		nPosBegin = 1
		nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
		
		If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
		 
		vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
		nDataBoundPos = InstrB(1, biData, vDataBounds)
		
		Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
			
			nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
			nPos = InstrB(nPos, biData, CByteString("name="))
			nPosBegin = nPos + 6
			nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
			sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
			nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
			nPosBound = InstrB(nPosEnd, biData, vDataBounds)
			
			If nPosFile <> 0 And  nPosFile < nPosBound Then
				Dim oUploadFile, sFileName
				Set oUploadFile = New UploadedFile
				
				nPosBegin = nPosFile + 10
				nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
				sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
				oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))

				nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
				nPosBegin = nPos + 14
				nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
				
				oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
				
				nPosBegin = nPosEnd+4
				nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
				oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
				
				If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
			Else
				nPos = InstrB(nPos, biData, CByteString(Chr(13)))
				nPosBegin = nPos + 4
				nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
				If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
			End If

			nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
		Loop
	End Sub

	'String to byte string conversion
	Private Function CByteString(sString)
		Dim nIndex
		For nIndex = 1 to Len(sString)
		   CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
		Next
	End Function

	'Byte string to string conversion
	Private Function CWideString(bsString)
		Dim nIndex
		CWideString =""
		For nIndex = 1 to LenB(bsString)
		   CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
		Next
	End Function
End Class

Class UploadedFile
	Public ContentType
	Public FileName
	Public FileData
	
	Public Property Get FileSize()
		FileSize = LenB(FileData)
	End Property

	Public Sub SaveToDisk(sPath)
		Dim oFS, oFile
		Dim nIndex
	
		If sPath = "" Or FileName = "" Then Exit Sub
		If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
	
		Set oFS = Server.CreateObject("Scripting.FileSystemObject")
		If Not oFS.FolderExists(sPath) Then Exit Sub
		
		Set oFile = oFS.CreateTextFile(sPath & FileName, True)
		
		For nIndex = 1 to LenB(FileData)
		    oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
		Next

		oFile.Close
	End Sub
	
	Public Sub SaveToDatabase(ByRef oField)
		If LenB(FileData) = 0 Then Exit Sub
		
		If IsObject(oField) Then
			oField.AppendChunk FileData
		End If
	End Sub

End Class
%>


pls help me out. thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 15th, 2005, 08:15
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Re: Uploading file

This is cause by not uniquely naming your file controls:-
Code: Select all
<INPUT TYPE=FILE SIZE=70 NAME="FILE1">
<input name="hdSaveTo" type="hidden" id="hdSaveTo" value="disk">
<INPUT TYPE=FILE SIZE=70 NAME="FILE1">
<input name="hdSaveTo" type="hidden" id="hdSaveTo" value="disk">
Change their NAME and ID attributes to be unique
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 15th, 2005, 10:34
New Member
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Uploading file

thanks. what about

Code: Select all
If Uploader.Form("hdSaveTo") = "disk" Then
do i have to put another line for the other file control? or do i just stick with it?

Code: Select all
<INPUT TYPE=FILE SIZE=70 NAME="FILE1">
<input name="hdSaveTo" type="hidden" id="hdSaveTo" value="disk">
<INPUT TYPE=FILE SIZE=70 NAME="FILE2">
<input name="hdSaveTo2" type="hidden" id="hdSaveTo2" value="disk">
is that what you mean by your post?

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 21st, 2005, 08:14
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Re: Uploading file

Yes, you have the input lines correct now.

You will need conditional checks for each file....
you already have this:-
Code: Select all
If Uploader.Form("hdSaveTo") = "disk" Then
You need one (and the other code) for each file.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Dec 29th, 2005, 05:18
New Member
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Uploading file

thanks. ive done what you have said, but then now a newer problem arised. the database tells me this

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

do you know what this means? thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
uploading, file

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
weird uploading file begeiste PHP Forum 5 Sep 20th, 2007 05:05
PHP Support for File Uploading Sporky PHP Forum 2 Apr 19th, 2007 21:09
Creating a log file (text file) and an XML file using XSL kdelacruz Other Programming Languages 1 Nov 4th, 2006 21:12
Uploading visitors file to my site pokerskatershark Web Page Design 8 Jan 17th, 2006 01:22


All times are GMT. The time now is 06:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42