Click to See Complete Forum and Search --> : Problem with adding captions to image upload facility


kessa
06-12-2006, 05:22 AM
Hi All,

I currently have an image upload facility on my site which uses Pure ASP upload 2.1.6 which, at the moment, only allows the uploading of images.

What I would like to do is allow a caption to be added for each image - but for some reason I can't seem to get the following script to update the database.


If (CStr(Request.QueryString("GP_upload")) <> "") Then
strsql = "UPDATE ads SET "
strsql = strsql & " caption1 = '" & padQuotes(trim(cstr(request("caption1"))))& "',"
strsql = strsql & " caption2 = '" & padQuotes(trim(cstr(request("caption2"))))& "',"
strsql = strsql & " caption3 = '" & padQuotes(trim(cstr(request("caption3"))))& "',"
strsql = strsql & " caption4 = '" & padQuotes(trim(cstr(request("caption4"))))& "',"
strsql = strsql & " caption5 = '" & padQuotes(trim(cstr(request("caption5"))))& "',"
strsql = strsql & " caption6 = '" & padQuotes(trim(cstr(request("caption6"))))& "',"
strsql = strsql & " caption7 = '" & padQuotes(trim(cstr(request("caption7"))))& "',"
strsql = strsql & " caption8 = '" & padQuotes(trim(cstr(request("caption8"))))& "',"
strsql = strsql & " caption9 = '" & padQuotes(trim(cstr(request("caption9"))))& "',"
strsql = strsql & " caption10 = '" & padQuotes(trim(cstr(request("caption10"))))& "',"
strsql = strsql & " lastupdated = '" &date&" "& time& "',"
strsql = strsql & " step5comp=1 "
strsql = strsql & " WHERE ownersidx =" & session("ownersidx") & " AND adsidx=" & request("propertyidx")
objconn.Execute(strsql)
end if


It seems to be a problem with getting the details from the form because if I enter a value directly into the update:

For example:


strsql = strsql & " caption1 = 'test',"


.... it works fine

I've also tried changing:


If (CStr(Request.QueryString("GP_upload")) <> "") Then


to ...


If (CStr(UploadFormRequest("MM_update")) = "form1" And CStr(UploadFormRequest("MM_recordId")) <> "") Then


... and to ...


if request.form("Submit")="Upload images" then


..but neither worked.

Does anyone know what may be going wrong here as I've not encountered this problem before.

The code for the form itself is:


<form action="<%=MM_editAction%>" method="post" enctype="multipart/form-data" name="form1" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP',false,150,200,200,600,600,'','');showProgressWindow('upload. htm',400,150);return document.MM_returnValue" id="form">

<% for icount = 1 to var_max_photo %>

<fieldset class="adminupload">
<legend>Photo <%= (icount) %></legend>

<% if rs2("photo"&icount)>"" then %>
<img src="photos/<%= rs2("photo"&icount)%>" alt="" class="thumbnail" />
<% else %>
<img src="../../images/nophoto.gif" class="thumbnail" alt="" />
<% end if %>

<label for="photo<%= (icount) %>"><span>Select File </span></label>
<input name="photo<%= (icount) %>" type="file" id="photo<%= (icount) %>" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP',false,250,200,200,600,600,'','')" /><br />
<label for="caption<%= (icount) %>"><span>Caption</span></label>
<input name="caption<%= (icount) %>" type="text" id="caption<%= (icount) %>" size="34" maxlength="37" value="<%= Recordset1.Fields.Item("caption"&icount).Value %>" />
<br />
</fieldset>

<% next %>

<p align="center">
<input name="Submit" type="submit" value="Upload images" />
</p>

<input type="hidden" name="MM_update" id="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("propertyidx").Value %>" />
<input type="hidden" name="propertyidx" id="propertyidx" value="<%= request("propertyidx") %>" />
</form>


Thanks
Kessa

russell
06-12-2006, 06:14 PM
can't combine binary with ascii data -- meaning that the image upload gets the form data via Request.BinaryRead -- which disallows the use of Request.Form, Request.QueryString or Request in the same script.

You'll need to read the entire form contents with a binary read, then convert the binary to ASCII.

Or you can have two forms on seperate pages, one to get the caption with a Request.Form and the other to get the binary image data

russell
06-12-2006, 06:21 PM
How, you ask, do I convert the binary to ascii?

Function BinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function

kessa
06-13-2006, 05:55 AM
Hi Russell,

Ah, I see - that explains it :D

Thanks for the binary - ascii function too.

I'm still fairly new to .asp so would you mind telling me how I can hook that function into the code above? Do I just need to just place it before the UPDATE statement for the captions, or do I need to call it somehow?

Thanks so much - this has been bugging me for weeks!
Kessa

kessa
06-14-2006, 05:04 AM
Russell?... anyone? :o

russell
06-14-2006, 11:58 AM
Try something like this

Dim caption
Dim binCaption
binCaption= Request.BinaryRead("caption")

caption = BinaryToString(binCaption)

Response.Write caption

Function BinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function

kessa
06-14-2006, 04:35 PM
Hi Russell,

I tried adding that above the UPDATE statement but got the following error message:

"An unhandled data type was encountered."

I tried moving it to just above the form (in case it was the position of the function which was causing the problem), but I got the same error message.

The line which it didn't seem to like is the following bit:

"binCaption= Request.BinaryRead("caption")"

Any ideas?

Thanks
Kessa

russell
06-14-2006, 04:46 PM
sorry, was typing faster than i was thinking. can't binary read that way -- have to take the whole thing.

check this (http://www.intellidimension.com/default.rsp?topic=/pages/rdfgateway/reference/script/request_binaryRead.rsp) out -- let me know if it helps