Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload File with text

Status
Not open for further replies.

glb

Programmer
Sep 6, 2000
9
0
0
GB
Hi,

Can anyone help me with uploading a file with a message. I am using...

<FORM METHOD=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot; ACTION=&quot;UploadIt.asp&quot;>
<table width=&quot;70%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; align=&quot;center&quot;>
<tr>
<td><TEXTAREA wrap=&quot;on&quot; NAME=&quot;messagetxt&quot; TABINDEX=&quot;1&quot; ROWS=&quot;5&quot; COLS=&quot;70&quot;></TEXTAREA></td>
</tr>
<tr>
<td><P class=&quot;centerIt&quot;>Upload a picture to go with your message.</P></td>
</tr>
<tr>
<td align=&quot;center&quot; width=90%&quot; ><P>Filename:&nbsp;&nbsp;<INPUT TYPE=&quot;file&quot; NAME=&quot;userimage&quot; tabindex=&quot;2&quot;></P></td>
</tr>
<tr>
<td align=&quot;center&quot; ><input type=&quot;submit&quot; name=&quot;Upload&quot; value=&quot;Upload&quot; tabindex=&quot;4&quot;></td>
</tr>
</table>
</form>

As the form and...

<%

'some code here

MessageTxt = request(&quot;messagetxt&quot;)

Set Upload = Server.CreateObject(&quot;Persits.Upload.1&quot;)

Upload.OverwriteFiles = False
Upload.SetMaxSize 50000, true

Upload.Save &quot;bla bla bla&quot;

For Each File in Upload.Files
If File.ImageType <> &quot;GIF&quot; and File.ImageType <> &quot;JPG&quot; Then
File.Delete
Response.redirect &quot;bla bla bla&quot;
Response.End
exit for
end if
next

Set OBJdbConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
OBJdbConnection.ConnectionTimeout = Session(&quot;ConnectionTimeout&quot;)
OBJdbConnection.CommandTimeout = Session(&quot;CommandTimeout&quot;)
OBJdbConnection.Open Session(&quot;ConnectionString&quot;)

theSQL = &quot;insert into message_board &quot;
theSQL = theSQL & &quot;(sentby_username, messagetext, picture_link)&quot;
theSQL = theSQL & &quot; values ('&quot;&Session(&quot;username&quot;)&&quot;', '&quot;& MessageTxt &&quot;', '&quot; & NewImageFile & &quot;')&quot;

'*****Write to DB*****
OBJdbConnection.Execute(theSQL)
OBJdbConnection.close
Set OBJdbConnection = Nothing %>

...to process it.

The file gets uploaded but the MessageTxt part gets lost.

Is there any way round this and what am i missing?

Many thanks in advance.

Al
 
you have to use &quot;upload.form&quot; instead of the &quot;request&quot; object.
e.g.
MessageTxt = upload.form(&quot;messagetxt&quot;)

Hope this helps
Regards
Gus
 
Thanks Gus.

Still didn't work though!?! I have put the code you suggested after Set Upload = Server.CreateObject(&quot;Persits.Upload.1&quot;).

Any suggestions?

Many thanks.
Al
 
Try changing 'upload.save&quot;blah blah&quot;' to just 'upload.save'
Then set the uploaded file as an object e.g.
Set File = Upload.Files
Then use File.SaveAs&quot;blah blah blah&quot; to set the path to save the file upload.

Hope this helps
Gus
 
Sorry i didnt mean file.saveas.
i think there is file.path&quot;blah blah blah&quot; i would check in the instructions first.
They are pretty good.

Regards
Angus
 
Hi again,

Thanks for the help so far. I can now get the message text through.

One other problem has become apparent now though...

If no image is selected in the form the message text doesn't get through either and nothing is written to the DB. All is OK if there is message text and a file but not just a file to upload!

Can I check to see if there is a file to upload and if not just execute code to add the text to the DB?

Any ideas?

Many thanks again,
Al
 
I think something along these lines should solve your problem. Only if there is a file present does the if not statment evaluate as true and the code run.

Set File = Upload.Files


If Not File Is Nothing Then

file.path&quot;blah blah blah&quot;

For Each File in Upload.Files
If File.ImageType <> &quot;GIF&quot; and File.ImageType <> &quot;JPG&quot; Then
File.Delete
Response.redirect &quot;bla bla bla&quot;
Response.End
exit for
end if
next

End if


Hope I can help
Regards

Gus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top