Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- strFilePath = "C:\Users\DELL\Desktop\gt.png"
- UploadFile strFilePath, strUplStatus, strUplResponse
- MsgBox strUplStatus & vbCrLf & strUplResponse
- Sub UploadFile(strPath, strStatus, strResponse)
- Dim strFile, strBoundary, bytData, bytPayLoad
- On Error Resume Next
- With CreateObject("Scripting.FileSystemObject")
- If .FileExists(strPath) Then
- strFile = .GetFileName(strPath)
- Else
- strStatus = "File not found"
- Exit Sub
- End If
- End With
- With CreateObject("ADODB.Stream")
- .Type = 1
- .Mode = 3
- .Open
- .LoadFromFile strPath
- If Err.Number <> 0 Then
- strStatus = Err.Description & " (" & Err.Number & ")"
- Exit Sub
- End If
- bytData = .Read
- End With
- strBoundary = String(6, "-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")
- With CreateObject("ADODB.Stream")
- .Mode = 3
- .Charset = "Windows-1251"
- .Open
- .Type = 2
- .WriteText "--" & strBoundary & vbCrLf
- .WriteText "Content-Disposition: form-data; name=""upload_file""; filename=""" & strFile & """" & vbCrLf
- .WriteText "Content-Type: octet/stream" & vbCrLf & vbCrLf
- .Position = 0
- .Type = 1
- .Position = .Size
- .Write bytData
- .Position = 0
- .Type = 2
- .Position = .Size
- .WriteText vbCrLf & "--" & strBoundary & "--"
- .Position = 0
- .Type = 1
- bytPayLoad = .Read
- End With
- With CreateObject("MSXML2.ServerXMLHTTP")
- .SetTimeouts 0, 60000, 300000, 300000
- .Open "POST", "http://tessstt.esy.es/upload.php", False
- .SetRequestHeader "Content-type", "multipart/form-data; boundary=" & strBoundary
- .Send bytPayLoad
- If Err.Number <> 0 Then
- strStatus = Err.Description & " (" & Err.Number & ")"
- Else
- strStatus = .StatusText & " (" & .Status & ")"
- End If
- If .Status = "200" Then strResponse = .ResponseText
- End With
- End Sub
Add Comment
Please, Sign In to add comment