enctype="multipart/form-data" missing form data

Hi,

I know when you use enctype="multipart/form-data" you cannot access the data stored Request.Form.

So could you supply me with some code to access this data?

Marc
Form Code:
 
<form action="blogupdate.asp" method="post" enctype="multipart/form-data" name="New Blog" id="New Blog" style="margin-top:0px; margin-bottom:0px">
	<input name="Save_Action" type="hidden" id="Save_Action" value="New_Blog" />
	<input name="Blog_Creator" type="hidden" id="Blog_Creator" value="<%= struser%>" />
	<table width="518" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td style="padding-top:5px; padding-bottom:5px"><span class="style3">Blog Creator: <%= fullname%></span><br />
          <br />
          <input name="Blog_Date" type="text" class="style6" id="Blog_Date" value="<%= Now()%>" readonly="readonly" style="width:120px" /><br />
          <br />
          <input name="Blog_Title" type="text" class="style4" id="Blog_Title" value="Blog Title" style="width:400px" /><br />
          <br />
          <textarea name="Blog_Text" id="Blog_Text" style="color:#999999; font-family:Arial, Helvetica, sans-serif; width:400px; height:150px">Blog Text</textarea><br />
		  <br />
		  <span class="style3">Image</span><br />
          <input type="file" name="Blog_Image" id="Blog_Image" class="style6" style="width:404px" /><br />
          <br />
          Please note all new Blog's are to be vetted before they are viewable.<br />
		  <br />
		  <input type="submit" name="submit" id="submit" value="Save new Blog" /></td>
      </tr>
    </table></form>
 
Action Code:
 
If Request.Form("Save_Action") = "New_Blog" Then
	msql = "SELECT Blog_Main.Blog_ID, Blog_Main.Blog_Creator, Blog_Main.Blog_Title, Blog_Main.Blog_Date, Blog_Main.Blog_Text, Blog_Main.Blog_Image " & _
	"FROM Blog_Main " & _
	"WHERE Blog_ID = 0"
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open msql, objConn, adOpenDynamic, adLockOptimistic
	
	objRS.AddNew
	Dim strNewBlog_ID
	strNewBlog_ID = objRS("Blog_ID")
	objRS("Blog_Creator") = Request.Form("Blog_Creator")
	objRS("Blog_Title") = Request.Form("Blog_Title")
	objRS("Blog_Date") = Request.Form("Blog_Date")
	objRS("Blog_Text") = Request.Form("Blog_Text")
	If Request.Form("Blog_Image") <> "" Then
	  objRS("Blog_Image") = Request.Form("Blog_Image")
	Else
	  objRS("Blog_Image") = Null
	End If
	objRS.Update

Open in new window

marc_butlerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Louis01Commented:
Code is untested, so there might be an error or 2, but the general idea is here.
Assumption made: Views folder exists and is writable (IIS Properties)
<%
Response.Buffer=true
 
'The following three lines of code are used to make sure that this page is not cached on the client.
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
 
Server.ScriptTimeout = 1500
 
Sub BuildUploadRequest(RequestBin)
	'Get the boundary
	PosBeg = 1
	PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
	boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
	boundaryPos = InstrB(1,RequestBin,boundary)
	'Get all data inside the boundaries
	Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
		'Members variable of objects are put in a dictionary object
		Dim UploadControl
		Set UploadControl = CreateObject("Scripting.Dictionary")
		'Get an object name
		Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
		Pos = InstrB(Pos,RequestBin,getByteString("name="))
		PosBeg = Pos+6
		PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
		Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
		PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
		PosBound = InstrB(PosEnd,RequestBin,boundary)
		'Test if object is of file type
		If  PosFile<>0 AND (PosFile<PosBound) Then
			'Get Filename, content-type and content of file
			PosBeg = PosFile + 10
			PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
			FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
			'Add filename to dictionary object
			UploadControl.Add "FileName", FileName
			Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
			PosBeg = Pos+14
			PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
			'Add content-type to dictionary object
			ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
			UploadControl.Add "ContentType",ContentType
			'Get content of object
			PosBeg = PosEnd+4
			PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
			Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
			Else
			'Get content of object
			Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
			PosBeg = Pos+4
			PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
			Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
		End If
		'Add content to dictionary object
	UploadControl.Add "Value" , Value	
		'Add dictionary object to main dictionary
	UploadRequest.Add name, UploadControl	
		'Loop to next object
		BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
	Loop
 
End Sub
 
'String to byte string conversion
Function getByteString(StringStr)
 For i = 1 to Len(StringStr)
 	char = Mid(StringStr,i,1)
	getByteString = getByteString & chrB(AscB(char))
 Next
End Function
 
'Byte string to string conversion
Function getString(StringBin)
 getString =""
 For intCount = 1 to LenB(StringBin)
	getString = getString & chr(AscB(MidB(StringBin,intCount,1))) 
 Next
End Function
 
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
 
If Request.TotalBytes > (1000 * 1024) then '(1MB)
	Response.Write "The file size exceeds the allowed size of 1 MB."
	Response.end
end if
 
Response.Clear
byteCount = Request.TotalBytes
 
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
 
BuildUploadRequest  RequestBin
 
contentType = UploadRequest.Item("Blog_Image").Item("ContentType")
filepathname = UploadRequest.Item("Blog_Image").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("Blog_Image").Item("Value")
 
Save_Action = UploadRequest.Item("Save_Action").Item("Value")
Blog_Creator = UploadRequest.Item("Blog_Creator").Item("Value")
Blog_Date = UploadRequest.Item("Blog_Date").Item("Value")
Blog_Title = UploadRequest.Item("Blog_Title").Item("Value")
Blog_Text = UploadRequest.Item("Blog_Text").Item("Value") 'Not sure about using value on textbox - test...
Blog_Image = UploadRequest.Item("Blog_Image").Item("Value")
 
 
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-28 '28 = Length of this asp filename)
If filename <> "" then Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&"\Views\"&filename) 'Store in Views folder
if err.number <> 0 then
	Response.Write Err.Description & ".<br><br><br>"
	Response.Write "<b>The server does not allow the file to be uploaded to " & Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&"\Views\"&filename & ".<br>"
	Response.End
end if
 
On Error GoTo 0
dim myValue
For i = 1 to LenB(value)
 If filename <> "" then MyFile.Write chr(AscB(MidB(value,i,1)))
Next
	 
If filename <> "" then  MyFile.Close
 
on error goto 0
 
sFilePathName = Server.MapPath("Views/" & filename)
Set MyFile = ScriptObject.GetFile(sFilePathName)
Set MyStream = MyFile.OpenAsTextStream
 
Set connDB = CreateObject("ADODB.Connection")
connDB.Open Application("DBConnectionString")
Set rs = CreateObject("ADODB.Recordset")
sSQLq = "..."
rs.Open CStr(sSQLq), connDB, 1, 2
 
rs.AddNew 
rs("FileName") = filename
rs("Blog_Text") = Replace(Blog_Text, "'", "''") 
rs("ContentType") = ContentType
rs("BinaryDocument").AppendChunk value
rs.Update
rs.Close
		
MyStream.close
MyFile.Delete
%>

Open in new window

0
antonio1313Commented:
Send the other parameter on QueryString. REMEMBER querstring limit (2083 characters). A quick solution. The javascript can be made with a cycle of the elements in the form, but this would work.
<!-- FORM CODE -- >
<script language="javascript">
function sendForm() {
	name1 = document.something.name1.value;
	name2 = document.something.name2.value;
	url = "next_page.asp?name1=" + name1 + "&name2="  + name2;
	document.something.action = url;
	document.something.submit();
}
</script>
<table>
<form name="something" enctype="multipart/form-data">
	<tr>
		<td>Field one:<input type="text" name="name1" value=""></td>
	</tr>
	<tr>
		<td>Field two:<input type="text" name="name2" value=""></td>
	</tr>
	<tr>
		<td>File 1:<input type="file" name="oneFile"></td>
	</tr>
	<tr>
		<td>File 2:<input type="file" name="twoFile"></td>
	</tr>
	<tr>
		<td><input type="button" value="Upload" onClick="sendForm()"></td>
	</tr>
</form>
</table>
 
<!-- ACTION CODE -->
<%
name1 = request.QueryString("name1")
name2 = request.QueryString("name2")
 
sql = "SELECT * FROM table WHERE column=" & name1
...
...
...
THEN WRITE YOU CODE FOR UPLOADING THE FILES
%>

Open in new window

0
marc_butlerAuthor Commented:
Thats not a bad idea, I will do that and let you know the out come.

Marc
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

marc_butlerAuthor Commented:
One quick question?
How does the url respond to people putting a return in a multi line textfield?

Marc
0
marc_butlerAuthor Commented:
Hi antonio1313,

Ive tried your Java script but I get an error on page. Attached is my code;
<script language="javascript">
 
function SubmitForm() {
	Blog_Creator = document.New_Blog.Blog_Creator.value;
	Blog_Date = document.New_Blog.Blog_Date.value;
	Blog_Title = document.New_Blog.Blog_Title.value;
	Blog_Text = document.New_Blog.Blog_Text.value;
	url = "blogupdate.asp?Action=Upload&Blog_Creator=" + Blog_Creator + "&Blog_Date="  + Blog_Date + "&Blog_Title="  + Blog_Title + "&Blog_Text="  + Blog_Text;
	document.New_Blog.action = url;
	document.New_Blog.submit();
}
 
</script>
 
<form enctype="multipart/form-data" name="New_Blog" id="New_Blog" style="margin-top:0px; margin-bottom:0px">
	<input name="Blog_Creator" type="hidden" id="Blog_Creator" value="<%= struser%>" />
	<table width="518" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td style="padding-top:5px; padding-bottom:5px"><span class="style3">Blog Creator: <%= fullname%></span><br />
          <br />
          <input name="Blog_Date" type="text" class="style6" id="Blog_Date" value="<%= Now()%>" readonly="readonly" style="width:120px" /><br />
          <br />
          <input name="Blog_Title" type="text" class="style4" id="Blog_Title" value="Blog Title" style="width:400px" /><br />
          <br />
          <textarea name="Blog_Text" id="Blog_Text" style="color:#999999; font-family:Arial, Helvetica, sans-serif; width:400px; height:150px">Blog Text</textarea><br />
		  <br />
		  <span class="style3">Image</span><br />
          <input name="Blog_Image" type="file" class="style6" id="Blog_Image" size="48" />
          <br />
          <br />
          Please note all new Blog's are to be vetted before they are viewable.<br />
		  <br />
		  <input type="button" name="submit" id="submit" value="Save New Blog" onclick="SubmitForm()" /></td>
      </tr>
    </table></form>

Open in new window

0
marc_butlerAuthor Commented:
Hi antonio1313,

I have now sorted the problem and it is all up and running, but I still have one small problem.

The multi line textfield is abit of a pain due to it loosing its formatting on submit. I have got around this problem by getting my user's to use <br /> to end a line. But is there anyway I can keep the formatting on submit?
0
antonio1313Commented:
Sorry ... but I had a lot of work
Change the "Save New Blog" button type, submit => button


<!-- ACTION CODE -->
<%
longText = replace(request("Blog_Text"),chr(13),"<br>") 
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.