Helpful Information
 
 
Category: Visual Basic Programming
Http file upload (Post)

Does anyone know how to upload a file and form data
to a server?

What i want to do is allow a user to upload a file and form data
to my php script so i can process it. So of course FTP would be
no good.

I can do this with the XMLHTTP control but it does not thread and
it pretty lame. Surely you can do it with winsock or Inet

Any ideas?

Source code would be greatly appreciated.

Just a stupid question from me, but why not just have the user access the php page through a browser?

Another possible solution would be to use sockets but I have no code for you on that, the MSDN library might have some examples for you though.

Sorry forgot to mention, i have a VB program that the user uses and then they submit the info to the server. (a file and form fields)

Here is the URL for the XMLHTTP method
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=6076&lngWId=1

Try using the Webbrowser control from Microsoft Internet Controls to do your stuff. That's what I usually use, with code something like this:


Dim bPostData() As Byte
Dim sHeaders As String

sPost = "foo=1&bar=test&quux=42" ' Post data
sHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrlf ' Add extra headers as needed
ReDim bPostData(Len(sPost))
bPost = StrConv(sData, vbFromUnicode)
WebBrowser.Navigate sURL, 0, vbEmpty, bPostData, sHeaders
(or)
WebBrowser.Navigate2 sURL, 0, vbEmpty, bPostData, sHeaders

If you want to use a GET method instead of POST, then simply remove the extra params from the call and use WebBrowser.Navigate sURL or WebBrowser.Navigate2 sURL instead. I just put the above code together off the top of my head and haven't checked it to see if it actually works, but the syntax should be pretty close.

Hope this helps!

That method only works with Text files.

Klemens Schmid has some source on how to send a text file
using that method.

http://www.schmidks.de/files/HttpUpload2.zip

It works great but i get a weird error every second time i send
to the server.
The error is this:

Method Not Implemented
--AaB03x to / not supported.
Invalid method in request --AaB03x

The server is running Apache 1.3.26 (a freebie server)

Any ideas why it does this?










privacy (GDPR)