Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Http File Upload (post)

Recommended Posts

Does anyone know how to upload a file and form datato a server?What i want to do is allow a user to upload a file and form datato my php script so i can process it. So of course FTP would beno good.I can do this with the XMLHTTP control but it does not thread andit pretty lame. Surely you can do it with winsock or InetAny ideas?Source code would be greatly appreciated.

Share this post


Link to post
Share on other sites

Hi kvarnerexpress,

I've same problem with you, and after googling for days i didnt found what i want. but the basic for upload file is by sending "Content-Type: multipart/form-data" header. I used INET(Mic. Internet Transfer Control SP4) control for this. I've named this control INETPOST.

assuming the field name is "myfile" and the button name is "upload" for the upload form

' create sub for making upload postprivate sub upload_file()  dim strPOST as string, Header as string Boundary as string, uagent as string  dim Idboundary as string   ' id boundary for the site, it may different     uagent = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"  INETPOST.host = "somesite.com;  Idboundary = "9876543210123"	' you can generate this number  Boundary = String(27, "-") & Idboundary	 ' mutipart post need "-" sign     Header = uagent & vbCrLf & "Content-Type: multipart/form-data; " & "boundary=" & Boundary    strPOST = "--" & Boundary & vbCrLf & _  "Content-Disposition: form-data; name=""myfile""" & vbCrLf & vbCrLf & _  """ & EncodeBin & """ & vbCrLf & _ "--" & Boundary & vbCrLf & _ "Content-Disposition: form-data; name=""upload""" & vbCrLf & vbCrLf & _ "Upload File" & vbCrLf & _ "--" & Boundary & "--" & vbCrLf  INETPOST.Execute "http://http://www.somesite.com/upload.php&%2334;, "POST", strPOST, Header  ' Wait untill it finished  Do Until BekasNET.StillExecuting = False: DoEvents: Loopend sub' function to encode binary fileFunction EncodeBin(SourceFile As String)Dim buf As String, File1 As IntegerFile1 = FreeFileOpen SourceFile For Binary Access Read As #File1  ' make buffer to storing file's content  buf = Space(LOF(File1))  Get #File1, , bufClose #File1EncodeBin = bufEnd Function

Hope's help!! :D
Edited by masterio (see edit history)

Share this post


Link to post
Share on other sites

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

Assumptions that I made by reading your question and comments.
You have a server with PHP as a web script and you want to save a file from you users desktop/volume/share to the http server using an html form.

if this is correct you have to go to http://www.tizag.com/phpT/fileupload.php
I think this is what you looking for you can save information from a form to a database and upload a file to a server using PHP.

Hope this help!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.