yogaboy
Posts: 377 Joined: 5/22/2004 Status: offline
|
RE: File upload problem - 11/17/2004 6:44:29
I tried that - but I couldn't get it to work. First page takes the info, 2nd page inserts to the database and takes the filename via a browse button, and on submit uploads the file. Page 1 <input type="text" name="txtDocTitle"> Page 2 myDocTitle = Replace(Request.Form("txtDocTitle"), "'", "''") INSERT INTO KeyDocuments (DocTitle,...) VALUES ('" & myDocTitle & "'),... and <input type="file" name="filename"> etc etc on submit it runs the upload code etc 2 big problems with this (I've found) are that the user can fill out page one, and not upload a file on page 2. Second prob is that you have to get the user to put in the filename twice - once for the database and once for the upload. I think problem 2 can be solved if you're good with the FileSystemObject (I'm not!). Here's both pages of my code, the upload code I got from star developer I've been tinkering with these, so beware! They're here in the spirit of Open Source page 1<form name="frmKeyDocAdd" method="post" action="KeyDocInsert.asp">
<fieldset>
<legend>Your details</legend>
<table border="0" cellpadding="0" cellspacing="2">
<tr><td><p><select name="slctSubmittedBy">
<option value="" selected>Submitted by (pick a name)</option>
<%
mySQL1 = "SELECT NCSS_Code, FirstName, LastName FROM NCSS"
'SETTING RECORDSET OBJECT AND OPENING RECORDSET USING SQL STATEMENT
Set myRS = Server.CreateObject("ADODB.Recordset")
myRS.Open mySQL1, myConn
While Not myRS.EOF
myFName = myRS("FirstName")
myLName = myRS("LastName")
myID = myRS("NCSS_code")
Response.write "<option value='" & myID & "'>" & myFName & " " & myLName & "</option>"
myRS.MoveNext
Wend
Response.write "</select>"
myRS.Close
%>
</select><span class="req">*</span></p>
<tr><td><p><select name="slctName">
<option value="" selected>On behalf of (pick a name)</option>
<%
mySQL1 = "SELECT NCSS_Code, FirstName, LastName FROM NCSS"
'SETTING RECORDSET OBJECT AND OPENING RECORDSET USING SQL STATEMENT
Set myRS = Server.CreateObject("ADODB.Recordset")
myRS.Open mySQL1, myConn
While Not myRS.EOF
myFName = myRS("FirstName")
myLName = myRS("LastName")
myID = myRS("NCSS_code")
Response.write "<option value='" & myID & "'>" & myFName & " " & myLName & "</option>"
myRS.MoveNext
Wend
Response.write "</select>"
myRS.Close
%>
</p>
</td></tr>
<tr><td><p><select name="slctRegion">
<option value="" selected>Select your region</option>
<%
mySQL2 = "SELECT RegionName, RegionID FROM Regions"
myRS.Open mySQL2, myConn
While Not myRS.EOF
myRegion = myRS("RegionName")
Response.write "<option value='" & myRS("RegionID") & "'>" & myRegion & "</option>"
myRS.MoveNext
Wend
Response.write "</select>"
myRS.Close
%>
</select><span class="req">*</span></p>
</td></tr>
</table>
</fieldset>
</p>
<fieldset>
<legend>Document details</legend>
<table border="0" cellpadding="0" cellspacing="2">
<tr><td><p>
<select name="slctSection">
<option value="" selected="selected">Select section of website to put this info</option>
<option value="News">News</option>
<option value="Key Documents">Key Documents</option>
</select>
<br>(it will be automatically linked to your region)</p>
</td></tr>
<tr>
<td colspan="2"><p>Blurb about document<span class="req">*</span><br><textarea name="txtBlurb" rows="6" cols="60"></textarea></p></td>
</tr>
<tr>
<td><p>Do you have permission from the originator/author/copyright-owner to use this document?<span class="req">*</span></p></td><td width="50%"><p><input type="checkbox" name="chkPermission">Tick for yes!</p></td>
</tr>
</table>
</fieldset></p>
<fieldset>
<legend>Adding a document</legend>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td><p>If you are adding a document, do it here - otherwise, you can skip this bit.</p></td></tr>
<tr><td> </td></tr>
<tr><td><p>What is the TITLE of the document you wish to add<br><input type="text" name="name" size="60"></p></td></tr>
<tr><td><p>File name: <br><input type="file" name="File" size="60"></td></p></tr>
</table>
</fieldset>
</p>
<fieldset>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>You can submit this information now, or you can add more below in the advanced section and then submit</td>
</tr>
<tr>
<td align="center"><input type="submit" name="btnSubmit" value="Submit this document"</td>
</tr>
</table>
</fieldset>
</p>
</form> page 2 <!--#include file="Loader.asp"-->
<%
Response.Buffer = True
' load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
' File binary data
Dim fileData
fileData = load.getFileData("file")
' File name
Dim fileName
fileName = LCase(load.getFileName("file"))
' File path
Dim filePath
filePath = load.getFilePath("file")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("file")
' File size
Dim fileSize
fileSize = load.getFileSize("file")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("file")
' Content Type
Dim contentType
contentType = load.getContentType("file")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
nameInput = load.getValue("name")
' Path where file will be uploaded
Dim pathToFile
pathToFile = Server.mapPath("/documents/") & "\" & fileName
' Uploading file data
Dim fileUploaded
fileUploaded = load.saveToFile ("file", pathToFile)
' destroying load object
Set load = Nothing
%>
<!--#INCLUDE FILE="adovbs.inc"-->
<!--#INCLUDE FILE="dbconx_res.asp"-->
<%
dim myDocTitle, myCode, myRegionID, mySubmittedBy
dim myBlurb, myPermission, myFileName, myFormat, myFPath
dim myDay, myMonth, myYear
dim mySQL
dim myWebsiteSection
myDay = Day(Date)
myMonth = Month(Date)
myYear = Year(Date)
myDocTitle = Replace(Request.Form("name"), "'", "''")
myWebsiteSection = Request.Form("slctSection")
mySubmittedBy = Request.Form("slctSubmittedBy")
myCode = Request.Form("slctName")
myRegionID = Request.Form("slctRegion")
myBlurb = Replace(Request.Form("txtBlurb"), "'", "''")
myPermission = Request.Form("chkPermission")
myFileName = file
myFormat = Right(myFileName,3)
if myPermission = "on" then
myPermission = "Yes"
elseif myPermission = "" then
myPermission = "No"
ElseIf myPermission <> "on" then
myPermission = "No"
End If
mySQL = "INSERT INTO KeyDocuments (DocTitle, WebsiteSection, SubmittedBy, NCSS_Code, RegionID, Abstract, Permission, DaySubmitted, MonthSubmitted, YearSubmitted, FileFormat, FileName) VALUES ('" & myDocTitle & "', '" & myWebsiteSection & "', '" & mySubmittedBy & "', '" & myCode & "', '" & myRegionID & "', '" & myBlurb & "', '" & myPermission & "', '" & myDay & "', '" & myMonth & "', '" & myYear & "', '" & myFormat & "', '" & myFileName & "')"
myConn.Execute(mySQL)
myConn.Close
Set myConn = Nothing
%>
|