使用VB.net将文件和值上传到php脚本 [英] Upload file and values using VB.net to php-script

查看:59
本文介绍了使用VB.net将文件和值上传到php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我想在VB.net中有一些代码来上传文件和一些信息(比如这些名称和登录代码)人)。因此它必须像这些html格式一样执行。



Hello,

I want to have a little code in VB.net to upload a file AND some information (like the name and a login-code of these person). So it will have to perform like these html-form.

<FORM ACTION=".../file.php">
name: <INPUT NAME="nickname"><BR>
code: <INPUT NAME="code"><BR>
file: <input name="userfile" type="file" />
<INPUT TYPE=SUBMIT>
</FORM>





我已经找到了下面的代码,但我不知道如何实现昵称和登录代码...



感谢您的帮助,



wimvr



______________





I have already found the code below, but I don't know how to implement the nickname and the login-code...

Thanks for your help,

wimvr

______________

Dim filepath As String = TextboxSelectedFile.Text
Dim url As String = "www.mysite.be/file.php"

Dim boundary As String = IO.Path.GetRandomFileName
Dim header As New System.Text.StringBuilder()
header.AppendLine("--" & boundary)
header.Append("Content-Disposition: form-data; name=""userfile"";")
header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(filepath))
header.AppendLine()
header.AppendLine("Content-Type: application/octet-stream")
header.AppendLine()

Dim headerbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(header.ToString)
Dim endboundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(vbNewLine & "--" & boundary & "--" & vbNewLine)

Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
req.ContentType = "multipart/form-data; boundary=" & boundary
req.ContentLength = headerbytes.Length + New IO.FileInfo(filepath).Length + endboundarybytes.Length
req.Method = "POST"

Dim s As IO.Stream = req.GetRequestStream
s.Write(headerbytes, 0, headerbytes.Length)
Dim filebytes() As Byte = My.Computer.FileSystem.ReadAllBytes(filepath)
s.Write(filebytes, 0, filebytes.Length)
s.Write(endboundarybytes, 0, endboundarybytes.Length)
s.Close()

'Get the responds of these request
Dim resp As Net.HttpWebResponse = req.GetResponse()
Dim sresp As IO.Stream = resp.GetResponseStream()
Dim bytes(80000) As Byte
sresp.Read(bytes, 0, 80000)
Textbox1.Text = System.Text.Encoding.ASCII.GetChars(bytes)

推荐答案

使用multpart / form-data检查这个

链接

Check this one using multpart/form-data
Link


在php上放这个脚本



file.php

on php put this script

file.php
<?php 
 


target = cb_upload /;
target = "cb_upload/";


这篇关于使用VB.net将文件和值上传到php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆