ASP problem with upload

alejandroAT

Senior member
Apr 27, 2006
210
0
0
This thread has been edited....the original problem was solved (date transfer issues) and we have moved on to another as described in the current thread TItle.

----SCROLL DOWN FOR MORE--------



i m coding this website in asp and i seem to have ran against a wall.

The date i'm sending through the asp form changes completely once in gets written in the database. for example the input 7/6/2006 becomes 02/06/2448 once it enters the database.

let me describe the code:

i am using an asp page with a form.
this form contains 3 drop down boxes with the days, months, and years.
i then call a variable and add these 3 boxes together to give me the string that will be stored in the db.

like this:

Dim datestring
datestring = Request.Form("u_day") & "/" & Request.Form("u_month") & "/" & Request.Form("u_year")

and then procede to upload:

strSQL = "INSERT into Fdata ( stockID, fdate, quicklist, ftitle, category, description) values "
strSQL = strSQL & "(" & recordID & "," & datestring & "," & Request.Form("quicklist") & ",'" & Request.Form("ftitle") & "','" & categoryStr & "','" & Request.Form("description") & "')"
conn.execute (strSQL)

you can see above that i am inputing DATESTRING in a table called Fdata.

The process terminates without any errors and the value is added in the database....Only the number is nowhere near the same. The FDATE db column is set Date/Time > Short Date.

what is wrong with the whole thing i cannot understand.


 

Neverm1nd

Member
Jul 3, 2006
42
0
0
It would help to know what database you're using, but make sure the date format in windows locale settings (I don't know where you'd find the equivalent in *nix) are set to ddmmyyyy, or, if the DB server has it's own settings for date format. Otherwise, try entering the date in ISO 8601 (http://en.wikipedia.org/wiki/ISO_8601) format, i.e. YYYY-MM-DD (2006-06-07). Depending on the database, you may also need to enclose the date string in #'s or single quotes.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
Thnx for the reply Neverm1ind.

i am using access for the db. i tried to input the string as dd-mm-yyyy, mm-dd-yyyy, yyyy-mm-dd to see if its a format issue but it always goes wrong. I checked my PC date format (my pc is acting as the test server with IIS) and its dd/mm/yyyyy. the db format is also set as dd/mm/yyyy. Finally, the datestring is dd/mm/yyyy.
Also tried to put the datestring in single quotes :

datestring = 'Request.Form("u_day") & "/" & Request.Form("u_month") & "/" & Request.Form("u_year")'

this makes the whole argument turn into an invisible comment.
then i tried with double quotes:

datestring = "Request.Form("u_day") & "/" & Request.Form("u_month") & "/" & Request.Form("u_year")"

which returns and error saying that end of statement is required.

i am really lost.

 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
In access Date string need to be enclosed within #

SO try: datestring = "#" & Request.Form("u_day") & "/" & Request.Form("u_month") & "/" & Request.Form("u_year") & "#"
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
Single quotes would have worked as well. What was happening was that without the # to signify the text as a date, the data was being evaluated as an expression. In otherwords: Day divided by month divided by year.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
of course...how silly of me.

But now that it works i ran against the second wall and i shouldnt have. maybe you could waste some of your time on this little devil.

The date sorted above is part of a form filled by general characteristics of a db record entry. Once this information gets written in the db the user is forwarded to a second page that allows them to upload files relevant to the entry they just made (e.g. attach a word document).

But alas i am getting an error:

Error Type:
ADODB.Stream (0x800A0BBC)
Write to file failed.

Now.....i have set permissions for IUSR on all folders that are required for the asp upload. Gave full permissions for this account on Security, made them Shared on the network and i also made Web shares and allowed read/write everywhere for IUSR..... still the writing fails....all i could google out of it is that the permissions need to be set....

but i have done so and i still get the error.

any hints? any help is mostrly appreciated.
 

Neverm1nd

Member
Jul 3, 2006
42
0
0
You need to post your code. The file could be open (or you could inadvertedly try to open it several times), you may not have specified create and the file does not exits, or the file exists and is write protected, or NAV or similar softwar may be blocking access to underlying calls.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
the code might be a bit too long but i ll try.......

-------- 1 . the ADD A NEW RECORD PAGE --------

this code allows the user to add description through a form.....



<%@LANGUAGE="VBSCRIPT" CODEPAGE="28597"%>
<%
Session.LCID = 1032
SetLocale("EL")
Session.CodePage = 1253
Response.Charset="windows-1253"
%>
<!--#include file="Connections/preferences.asp" -->
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="1"
MM_authFailedURL="admin_access_denied.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
'
Dim conn
Dim rs
Dim categoryId

categoryFormId = trim(Cstr(Request.Form("sltCategory")))
if categoryFormId > "0" then
categoryId = categoryFormId
else
categoryId = "0"
end if

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Add Record</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">

<script language="JavaScript" src="verify.js"></script>
<script language=JavaScript>
<!--
function category_onchange(add_form) {
document.add_form.action = "add.asp"
document.add_form.submit();
}

function changeSelection(form_src_name, form_dest_name){

eval("document.add_form."+form_dest_name+".selectedIndex = document.add_form."+form_src_name+".selectedIndex");

}
-->
</script>

<style type="text/css">
<!--
body {
background-color: #FFFFFF;
margin: 0;
padding: 0;
}
h1 {
font-size: 16px;
color: #666666;
margin: 0px;
padding: 0px;
}
-->
</style>
</head>

<body>

<div style="background-color:#FFFFFF; text-align:left">
<h1><img******="images/bul01plus.jpg" width="35" height="41" align="absmiddle"> ???s???? ???e??? </h1>

<form action="process_add_data.asp" method="post" name="add_form" id="add_form" onsubmit="return verify()">

<table width="400" border="0" cellpadding="5" cellspacing="5" style="font-size:12px; font-family:'Trebuchet MS', Arial; color:#666666">
<tr>
<td align="right" valign="top">??t???:</td>
<td align="left" valign="top"><input name="ftitle" type="text" class="box5" id="ftitle" size="18" ></td>
</tr>
<tr>
<td width="100" align="right" valign="top">?µe??µ???a:</td>
<td align="left" valign="top">
<%
' Requests all the form ekements that may be passed
u_date=request.form("u_date")
u_month=request.form("u_month")
u_day=request.form("u_day")
u_year=request.form("u_year")
%>

<select size="1" name="u_day">
<% ' Start a loop to create the days of the month
for counter = 1 to 31 %>
<option <% ' Select the current day to display
if counter = day(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>

<select size="1" name="u_month">
<% ' Start a loop to create the twelve months of the year
for counter = 1 to 12 %>
<option <% ' Select the current month to display
if counter = month(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>

<select size="1" name="u_year">
<% ' Start a loop to create the years prior and previous
for counter = 1995 to 2010 %>
<option <% ' Select the current year to display
if counter =year(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>

</td>
</tr>
<tr>
<td height="80" align="right" valign="top">??d??:</td>
<td align="left" valign="top">
<select name="sltCategory" id="sltCategory" onchange="return category_onchange(add_form)">
<option value="0">---------------------------</option>
<%
'Make connection and set SQL statement
connectionStr = MM_GEDD_STRING

Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = connectionStr
conn.Open

Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_GEDD_STRING
rs.Source = "SELECT * FROM Category ORDER BY CategoryTitle "
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open()


if not (rs.eof and rs.bof) then
Do while not rs.eof
if categoryId = trim(Cstr(rs("ID"))) then
response.write "<option value='" & rs("ID") & "' selected>" & rs("CategoryTitle") & "</option>"
categoryTitle = rs("CategoryTitle")
else
response.write "<option value='" & rs("ID") & "'>" & rs("CategoryTitle") & "</option>"
end if

rs.MoveNext
Loop
end if
'close rs
rs.Close
%>
</select><br><br>
<select name="sltSubcategory" id="sltSubcategory">
<%
Dim SqlStr

sqlStr = "SELECT CategoryTitle FROM Category WHERE ID = " & categoryId
rs.Source = sqlStr
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open()

if not (rs.eof and rs.bof) then
categoryTitle = rs("CategoryTitle")
rs.close
end if
'Sublocation
if (categoryId > "0") then

%>
<option value="0"></option>
<%

sqlStr = "SELECT * FROM Subcategory WHERE TitleID = " & categoryId & " ORDER BY SubcategoryTitle"
rs.Source = sqlStr
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open()

if not (rs.eof and rs.bof) then
Do while not rs.eof
'TODO - change SubcategoryTitle to categoryId and link to both DB tables. then read out names and insert them..
%>
<option value="<%=rs("ID")%>"><%=rs("SubcategoryTitle")%></option>
<%
rs.MoveNext
Loop
end if
rs.MoveFirst
%>
<input type="hidden" name="0" value="<%=categoryTitle%>">
<%
if not (rs.eof and rs.bof) then
Do while not rs.eof
'TODO - change SubcategoryTitle to categoryId and link to both DB tables. then read out names and insert them..
%>
<input type="hidden" name="<%=rs("ID")%>" value="<%=rs("SubcategoryTitle")%>">
<%
rs.MoveNext
Loop
end if

'clear rs
Set rs = Nothing
'close connection
conn.Close
else
%>
<option value="0">----------------------</option><input type="hidden" name="0" value="<%=CategoryTitle%>">
<%
end if
%>
</select> </td>
</tr>
<tr>
<td align="right" valign="top">?µf???s? st?? ?????? Se??da:</td>
<td align="left" valign="top">
<select name="quicklist" id="quicklist">
<option value="1" selected>???</option>
<option value="2">???</option>
</select> </td>
</tr>
<tr>
<td align="right" valign="top">?e????af?:</td>
<td align="left" valign="top"><textarea name="description" cols="40" rows="4" id="description" class="box5"></textarea></td>
</tr>
<tr>
<td></td>
<td><input name="Submit" type="submit" value="???ST???"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="add_data">

</form>
</div>
</body>
</html>



---------Dont be confused by the long asp inside the from....all these category and subcategory variables just check to see if an entry is selected as e.g. PRESS in order to load the drop down menu with subcategories under PRESS and so on. This is to make sure that the imput is the same for all entries when it comes to categories....if the input is manual then spelling mistakes will inhibit these records to be filtered by category.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
this is the code included in preferences.asp

<%
Dim uploadsDirVarData
Dim MM_GEDD_STRING
Dim paperPathData

uploadsDirVarData = Request.ServerVariables("APPL_PHYSICAL_PATH") & "papers\"

MM_GEDD_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Request.ServerVariables("APPL_PHYSICAL_PATH") & "Connections/GEDDDB.mdb"

paperPathData = "papers/"
%>

------This is where i declare the folder path where the files need to be uploaded...needless to say the permissions for this folder are set for IUSR both through the NTFS security and the IIS interface. but it still wont allow me to write into it.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
THIS IS THE UPLOAD CODE THAT FOLLOWS WHEN THE FORM IS SUBMITTED...
It allows users to upload up to 5 files.


<%@LANGUAGE="VBSCRIPT" CODEPAGE="28597"%>
<%
Session.LCID = 1032
SetLocale("EL")
Session.CodePage = 1253
Response.Charset="windows-1253"
%>
<!--#include file="Connections/preferences.asp" -->
<!-- #include file="freeaspupload.asp" -->
<%
Dim Upload, fileName, fileSize, ks, i, fileKey, addSection

addSection = Session("addSection")
Select case addSection
Case "fdata"
uploadsDir = uploadsDirVarComp
tableName = "Fdata"
tableID = "stockID"
end select

function SaveFiles
Set conn = Server.CreateObject("ADODB.Connection")
conn.open = MM_GEDD_STRING

recordID = Session("recordIDSession")


Set Upload = New FreeASPUpload
Upload.Save(uploadsDir)

' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>???e?a p?? µetaf?????a?:</B><br> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = "<br>" & SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) <br><br>"
'update file names in db table
strSQL = "UPDATE " & tableName & " SET " & fileKey & " = '" & Upload.UploadedFiles(fileKey).FileName & "' WHERE " & tableID & " = " & recordID
conn.execute (strSQL)

next
SaveFiles = SaveFiles & "? µetaf??? ?ta? ep?t????"
else

SaveFiles = "<form action='process_upload.asp' method='post' enctype='multipart/form-data' name='add_form' id='add_form' onsubmit='return verifyUpload()'>"
SaveFiles = SaveFiles & "<h1>???te???? ???e?a</h1><table width='430' border='0' cellpadding='3' cellspacing='3' class='box3'>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'><b>???e?? (1):</b></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='attachment1' type='file' id='attachment1' size='30'></td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'><b>???e?? (2):</b></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='attachment2' type='file' id='attachment2' size='30'></td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'><b>???e?? (3):</b></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='attachment3' type='file' id='attachment3' size='30'></td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'><b>???e?? (4):</b></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='attachment4' type='file' id='attachment4' size='30'></td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'><b>???e?? (5):</b></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='attachment5' type='file' id='attachment5' size='30'>"
SaveFiles = SaveFiles & "</td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "<tr valign='middle'>"
SaveFiles = SaveFiles & "<td width='80' align='right' bgcolor='#CCCCCC'></td>"
SaveFiles = SaveFiles & "<td colspan='2'><input name='Submit' type='submit' class='searchbox' value='???ST???'>"
SaveFiles = SaveFiles & "</td>"
SaveFiles = SaveFiles & "</tr>"
SaveFiles = SaveFiles & "</table>"
end if
conn.Close
Set conn = Nothing
end function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Add</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
<script language="JavaScript" src="verify.js"></script>
<style type="text/css">
<!--
body,td,th {
background-color:#FFFFFF;
font-family: "Trebuchet MS", Arial;
font-size: 11px;
color: #333333;
}
h1 {
font-size: 14px;
color: #666666;
}
-->
</style>
</head>
<body>
<div class="textarea">
<% response.write SaveFiles() %>
</div>
</body>
</html>
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
Finally this is the code that adds the data--------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="28597"%>
<%
Session.LCID = 1032
SetLocale("EL")
Session.CodePage = 1253
Response.Charset="windows-1253"
%>

<!--#include file="Connections/preferences.asp" -->


<%
Dim strSQL
Dim conn
Dim rs
Dim recordID
Dim categoryStr

If (CStr(Request("MM_insert")) = "add_data") Then

'Get the ID of the last entry in the databse then increment by one and add new record to databses.
connectionStr = MM_GEDD_STRING

Set conn = Server.CreateObject("ADODB.Connection")
conn.open = connectionStr

Set rs = conn.Execute("SELECT MAX(stockID) FROM Fdata")

if (isnull(rs(0))) then
recordID = 0
else
recordID = rs(0)
end if

rs.Close
Set rs = Nothing

if (Request.Form("sltSubcategory") > 0) then
Set rs = conn.Execute("SELECT SubcategoryTitle FROM Subcategory WHERE ID=" & Request.Form("sltSubcategory"))
categoryStr = rs(0) ' Store the value of the new identity in variable intNewID
rs.Close
Set rs = Nothing

else
Set rs = conn.Execute("SELECT CategoryTitle FROM Category WHERE ID=" & Request.Form("sltcategory"))
categoryStr = rs(0) ' Store the value of the new identity in variable intNewID
rs.Close
Set rs = Nothing

end if

recordID = recordID + 1
Session("recordIDSession") = recordID
Session("addSection") = "data"


Dim datestring
datestring = "#" & Request.Form("u_day") & "/" & Request.Form("u_month") & "/" & Request.Form("u_year") & "#"

'DB
strSQL = "INSERT into Fdata ( stockID, fdate, quicklist, ftitle, category, description) values "
strSQL = strSQL & "(" & recordID & "," & datestring & "," & Request.Form("quicklist") & ",'" & Request.Form("ftitle") & "','" & categoryStr & "','" & Request.Form("description") & "')"
conn.execute (strSQL)



conn.Close
Set conn = Nothing

response.redirect "process_upload.asp"
else
response.redirect "add.asp"
end if
%>
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
there is an external file being included called freeASPUpload which is what the name suggests...a script that i found on the net which is free to use....i have tested it in the past and it works...here it ....
---------------------------------------------

<%
' For examples, documentation, and your own free copy, go to:
' http://www.freeaspupload.net
' Note: You can copy and use this script for free and you can make changes
' to the code, but you cannot remove the above comment.

Class FreeASPUpload
Public UploadedFiles
Public FormElements

Private VarArrayBinRequest
Private StreamRequest
Private uploadedYet

Private Sub Class_Initialize()
Set UploadedFiles = Server.CreateObject("Scripting.Dictionary")
Set FormElements = Server.CreateObject("Scripting.Dictionary")
Set StreamRequest = Server.CreateObject("ADODB.Stream")
StreamRequest.Type = 1 'adTypeBinary
StreamRequest.Open
uploadedYet = false
End Sub

Private Sub Class_Terminate()
If IsObject(UploadedFiles) Then
UploadedFiles.RemoveAll()
Set UploadedFiles = Nothing
End If
If IsObject(FormElements) Then
FormElements.RemoveAll()
Set FormElements = Nothing
End If
StreamRequest.Close
Set StreamRequest = Nothing
End Sub

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

Public Property Get Files()
Files = UploadedFiles.Items
End Property

'Calls Upload to extract the data from the binary request and then saves the uploaded files
Public Sub Save(path)
Dim streamFile, fileItem

if Right(path, 1) <> "\" then path = path & "\"

if not uploadedYet then Upload

For Each fileItem In UploadedFiles.Items
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = 1
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & fileItem.FileName, 2
streamFile.close
Set streamFile = Nothing
fileItem.Path = path & fileItem.FileName
Next
End Sub

Public Function SaveBinRequest(path) ' For debugging purposes
StreamRequest.SaveToFile path & "\debugStream.bin", 2
End Function

Public Sub DumpData() 'only works if files are plain text
Dim i, aKeys, f
response.write "Form Items:<br>"
aKeys = FormElements.Keys
For i = 0 To FormElements.Count -1 ' Iterate the array
response.write aKeys(i) & " = " & FormElements.Item(aKeys(i)) & "<BR>"
Next
response.write "Uploaded Files:<br>"
For Each f In UploadedFiles.Items
response.write "Name: " & f.FileName & "<br>"
response.write "Type: " & f.ContentType & "<br>"
response.write "Start: " & f.Start & "<br>"
response.write "Size: " & f.Length & "<br>"
Next
End Sub

Private Sub Upload()
Dim nCurPos, nDataBoundPos, nLastSepPos
Dim nPosFile, nPosBound
Dim sFieldName, osPathSep, auxStr

'RFC1867 Tokens
Dim vDataSep
Dim tNewLine, tDoubleQuotes, tTerm, tFilename, tName, tContentDisp, tContentType
tNewLine = Byte2String(Chr(13))
tDoubleQuotes = Byte2String(Chr(34))
tTerm = Byte2String("--")
tFilename = Byte2String("filename=""")
tName = Byte2String("name=""")
tContentDisp = Byte2String("Content-Disposition")
tContentType = Byte2String("Content-Type:")

uploadedYet = true

on error resume next
VarArrayBinRequest = Request.BinaryRead(Request.TotalBytes)
if Err.Number <> 0 then
response.write "<br><br><B>System reported this error:</B><p>"
response.write Err.Description & "<p>"
response.write "The most likely cause for this error is the incorrect setup of AspMaxRequestEntityAllowed in IIS MetaBase. Please see instructions in the <A HREF='http://www.freeaspupload.net/freeaspupload/requirements.asp'>requirements page of freeaspupload.net</A>.<p>"
Exit Sub
end if
on error goto 0 'reset error handling

nCurPos = FindToken(tNewLine,1) 'Note: nCurPos is 1-based (and so is InstrB, MidB, etc)

If nCurPos <= 1 Then Exit Sub

'vDataSep is a separator like -----------------------------21763138716045
vDataSep = MidB(VarArrayBinRequest, 1, nCurPos-1)

'Start of current separator
nDataBoundPos = 1

'Beginning of last line
nLastSepPos = FindToken(vDataSep & tTerm, 1)

Do Until nDataBoundPos = nLastSepPos

nCurPos = SkipToken(tContentDisp, nDataBoundPos)
nCurPos = SkipToken(tName, nCurPos)
sFieldName = ExtractField(tDoubleQuotes, nCurPos)

nPosFile = FindToken(tFilename, nCurPos)
nPosBound = FindToken(vDataSep, nCurPos)

If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile
Set oUploadFile = New UploadedFile

nCurPos = SkipToken(tFilename, nCurPos)
auxStr = ExtractField(tDoubleQuotes, nCurPos)
' We are interested only in the name of the file, not the whole path
' Path separator is \ in windows, / in UNIX
' While IE seems to put the whole pathname in the stream, Mozilla seem to
' only put the actual file name, so UNIX paths may be rare. But not impossible.
osPathSep = "\"
if InStr(auxStr, osPathSep) = 0 then osPathSep = "/"
oUploadFile.FileName = Right(auxStr, Len(auxStr)-InStrRev(auxStr, osPathSep))

if (Len(oUploadFile.FileName) > 0) then 'File field not left empty
nCurPos = SkipToken(tContentType, nCurPos)

auxStr = ExtractField(tNewLine, nCurPos)
' NN on UNIX puts things like this in the streaa:
' ?? python py type=?? python application/x-python
oUploadFile.ContentType = Right(auxStr, Len(auxStr)-InStrRev(auxStr, " "))
nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line

oUploadFile.Start = nCurPos-1
oUploadFile.Length = FindToken(vDataSep, nCurPos) - 2 - nCurPos

If oUploadFile.Length > 0 Then UploadedFiles.Add LCase(sFieldName), oUploadFile
End If
Else
Dim nEndOfData
nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
nEndOfData = FindToken(vDataSep, nCurPos) - 2
If Not FormElements.Exists(LCase(sFieldName)) Then FormElements.Add LCase(sFieldName), String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))
End If

'Advance to next separator
nDataBoundPos = FindToken(vDataSep, nCurPos)
Loop
StreamRequest.Write(VarArrayBinRequest)
End Sub

Private Function SkipToken(sToken, nStart)
SkipToken = InstrB(nStart, VarArrayBinRequest, sToken)
If SkipToken = 0 then
Response.write "Error in parsing uploaded binary request."
Response.End
end if
SkipToken = SkipToken + LenB(sToken)
End Function

Private Function FindToken(sToken, nStart)
FindToken = InstrB(nStart, VarArrayBinRequest, sToken)
End Function

Private Function ExtractField(sToken, nStart)
Dim nEnd
nEnd = InstrB(nStart, VarArrayBinRequest, sToken)
If nEnd = 0 then
Response.write "Error in parsing uploaded binary request."
Response.End
end if
ExtractField = String2Byte(MidB(VarArrayBinRequest, nStart, nEnd-nStart))
End Function

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

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

Class UploadedFile
Public ContentType
Public Start
Public Length
Public Path
Private nameOfFile

' Need to remove characters that are valid in UNIX, but not in Windows
Public Property Let FileName(fN)
nameOfFile = fN
nameOfFile = SubstNoReg(nameOfFile, "\", "_")
nameOfFile = SubstNoReg(nameOfFile, "/", "_")
nameOfFile = SubstNoReg(nameOfFile, ":", "_")
nameOfFile = SubstNoReg(nameOfFile, "*", "_")
nameOfFile = SubstNoReg(nameOfFile, "?", "_")
nameOfFile = SubstNoReg(nameOfFile, """", "_")
nameOfFile = SubstNoReg(nameOfFile, "<", "_")
nameOfFile = SubstNoReg(nameOfFile, ">", "_")
nameOfFile = SubstNoReg(nameOfFile, "|", "_")
End Property

Public Property Get FileName()
FileName = nameOfFile
End Property

'Public Property Get FileN()ame
End Class


' Does not depend on RegEx, which is not available on older VBScript
' Is not recursive, which means it will not run out of stack space
Function SubstNoReg(initialStr, oldStr, newStr)
Dim currentPos, oldStrPos, skip
If IsNull(initialStr) Or Len(initialStr) = 0 Then
SubstNoReg = ""
ElseIf IsNull(oldStr) Or Len(oldStr) = 0 Then
SubstNoReg = initialStr
Else
If IsNull(newStr) Then newStr = ""
currentPos = 1
oldStrPos = 0
SubstNoReg = ""
skip = Len(oldStr)
Do While currentPos <= Len(initialStr)
oldStrPos = InStr(currentPos, initialStr, oldStr)
If oldStrPos = 0 Then
SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, Len(initialStr) - currentPos + 1)
currentPos = Len(initialStr) + 1
Else
SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, oldStrPos - currentPos) & newStr
currentPos = oldStrPos + skip
End If
Loop
End If
End Function
%>
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
so here it is......

the part that writes the description in the db works fine.
the second part where the attachments are to be uploaded doesn't work.

if you can find from the code above what is wrong...then....you rule.
 

alejandroAT

Senior member
Apr 27, 2006
210
0
0
right......fixed it......sorry for wasting your time ppl but my it was my own stupidity that was to blame... the path variable name was wrong.