May 16, 2008

Http File Upload (post)

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

Http File Upload (post)

kvarnerexpress
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.

Reply

Inspiron
I'm not sure if this is what you are looking for..
Check it out...
http://www.vb-helper.com/howto_upload_files.html

Otherwise use the FTP protocol method...
http://www.vb-helper.com/howto_ftp.html

Reply

sinmin
There are have FTP to be transfer file. I never been hear that using http to trasmit file le...

Reply

masterio
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

CODE
' create sub for making upload post
private 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 = "www.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://www.somesite.com/upload.php", "POST", strPOST, Header

  ' Wait untill it finished
  Do Until BekasNET.StillExecuting = False: DoEvents: Loop
end sub

' function to encode binary file
Function EncodeBin(SourceFile As String)
Dim buf As String, File1 As Integer

File1 = FreeFile

Open SourceFile For Binary Access Read As #File1
  ' make buffer to storing file's content
  buf = Space(LOF(File1))
  Get #File1, , buf
Close #File1

EncodeBin = buf

End Function


Hope's help!! biggrin.gif

 

 

 


Reply

adiaz01
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!!


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for http, file, upload, post
advertisement



Http File Upload (post)



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE