This question references: <b>How to upload a document, store its name and properties in a database, using ASP Classic with VB and do it for free!</b> and is a continuation....
I've used the solution referenced here:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=8525&lngWId=4But the problem is: when the file is uploaded it uploads EMPTY!!! Meaning, the name of the file is put on the server, but the contents of the file are missing and when you open it, there's nothing there.
Here's the modified code I've written:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#INCLUDE FILE="clsUpload.asp"-->
<%
'THIS WRITES TO THE DATABASE
Dim objUpload
Dim strFileName, strID, strPID, strDocCat, strDesc, strDocLoc, strDisp, strDateAdded, strBytes
Dim objConn
Dim objRs
Dim lngFileID
' Instantiate Upload Class
Set objUpload = New clsUpload
' Grab the form fields
strID = objUpload.Fields("ID").val
ue
strPID = objUpload.Fields("PID").va
lue
strFileName = objUpload.Fields("doc_name
").value
strDocCat = objUpload.Fields("doc_cate
gory").val
ue
strDesc = objUpload.Fields("descript
ion").valu
e
strDocLoc = objUpload.Fields("DocLoc")
.value
strDisp = objUpload.Fields("display"
).value
strDateAdded = objUpload.Fields("date_add
ed").value
'Response.Write(strID)
'Response.Write(strPID)
'Response.Write(strFileNam
e)
'Response.Write(strDocCat)
'Response.Write(strDesc)
'Response.Write(strDocLoc)
'Response.Write(strDisp)
'Response.Write(strDateAdd
ed)
Set objConn = Server.CreateObject("ADODB
.Connectio
n")
Set objRs = Server.CreateObject("ADODB
.Recordset
")
' Sometimes I personally have errors with one method on different servers, but the other works.
'objConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Files.mdb"
)
'objConn.Open "PROVIDER=Microsoft.Jet.OL
EDB.4.0;Da
ta Source=" & Server.MapPath("Files.mdb"
)
'ACCESS
'objConn.Open "PROVIDER=Microsoft.Jet.OL
EDB.4.0;Da
ta Source=F:\\0\\1\\131\\30\\
1620682\\u
ser\\17467
53\\htdocs
\\db\\dbna
me.db;UID=
userid;PWD
=password;
Persist Security Info=False"
'MS SQL
objConn.Open "Provider=sqloledb; Data Source=205.178.152.124; Initial Catalog=webprojectsql; User Id=F:\0\1\131\30\1620682\u
ser\174675
3\htdocs\d
b\dbname.d
b; User Id=userid; Password=password"
objRs.Open "documents", objConn, 3, 3
objRs.AddNew
objRs.Fields("ID").Value = strID
objRs.Fields("PID").Value = strPID
objRs.Fields("doc_name").V
alue = strFileName
objRs.Fields("doc_category
").Value = strDocCat
objRs.Fields("doc_descript
ion").Valu
e = strDesc
objRs.Fields("doc_location
").Value = strDocLoc
objRs.Fields("active").Val
ue = strDisp
objRs.Fields("date_added")
.Value = strDateAdded
objRs.Update
objRs.Close
lngFileID = strID
%>
<%
'THIS WRITES TO THE FILE SYSTEM!
Dim strPath
' Grab the file name
' strFileName = objUpload.Fields("doc_name
").FileNam
e
' Compile path to save file to
' strPath = Server.MapPath("Uploads") & "\" & strFileName
strPath = "F:\0\1\131\30\1620682\use
r\1746753\
htdocs\web
project\co
ntent" & "\" & strFileName
'Response.Write(strPath)
' Save the binary data to the file system
objUpload("doc_name").Save
As strPath
' Release upload object from memory
Set objRs = Nothing
Set objConn = Nothing
Set objUpload = Nothing
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document Saved</title>
<link href="css/general.css" rel="stylesheet" type="text/css" />
<table width="35%" border="0" align="center" cellpadding="3" cellspacing="2" class="silverinset">
<tr class="titlecentercell">
<td>Your Document, <%= strFileName %>, has been saved successfully and uploaded!</td>
</tr>
<tr>
<td align="center"><input name="goBack" type="button" class="small" onclick="location.href='li
st-subproj
ect-items.
asp?pid=<%
= Session("SV_PID") %>'" value="Return to Project Detail" /></td>
</tr>
</table>
<p> </p>
</body>
</html>
It all works fine, again, except the file contents are NOT uploaded with the file name. It's empty and all that's there is a 1K file with a name and nothing in the file itself.
Thanks.
Peter