Click here to Skip to main content
       

Visual Basic

 
GeneralRe: How to read list of local and network printers [modified] PinmemberKASR126-Dec-12 23:15 
GeneralRe: How to read list of local and network printers PinmemberEddy Vluggen27-Dec-12 4:28 
GeneralRe: How to read list of local and network printers PinmemberKASR127-Dec-12 7:26 
GeneralAdding an email notification module to my application. PinmemberKismetGerald24-Dec-12 13:01 
GeneralRe: Adding an email notification module to my application. PinmvpRichard MacCutchan24-Dec-12 23:07 
GeneralRe: Adding an email notification module to my application. PinmemberKismetGerald25-Dec-12 0:09 
GeneralRe: Adding an email notification module to my application. PinmvpRichard MacCutchan25-Dec-12 21:01 
Questionvbs - text inputs uploaded to web Pinmemberoceaniana24-Dec-12 12:25 
Hi, im not a programmer, but trying to get the below to work, my text file in C drive it needs to be read one line at a time and each line sent to the php input
 
The php script on the test server works fine
http://home.exetel.com.au/upload/dataupload.php?action=get&pcinfo=pcinfo&exceldata1=exceldata1&exceldata2=exceldata2&exceldata3=exceldata3[^]
 
and the results page for excel is set
http://home.exetel.com.au/upload/dataupload.html[^]
 
This is the vbscript, but its for full file upload, i need it to read my text file in C:\Temp3\Test.txt, and each line to be passed on its own argument and then to be uploaded.
 
Code
'fupload.vbs %homedrive%\Temp3\Test.txt http://home.exetel.com.au/upload/dataupload.php pcinfo
' need extra arguments for to pass on exceldata1 exceldata2 exceldata3 etc
'
'Upload file using http protocol And multipart/form-data
'v1.01
'2001 Antonin Foller, PSTRUH Software
do_vbsUpload
 
Sub do_vbsUpload()
  'We need at least two arguments (File + URL)
  If WScript.Arguments.Count < 2 Then InfoEcho
  
  'Are some required objects missing?
  If InStr(CheckRequirements, "Error") > 0 Then InfoEcho
  
  Dim FileName, DestURL, FieldName
  FieldName = "FileField" 'Default field name
  
  Dim aCounter, Arg
  aCounter = 1 'Argument counter
  For Each Arg In WScript.Arguments
    Select Case aCounter
      Case 1: FileName = Arg
      Case 2: DestURL = Arg
      Case 3: FieldName = Arg
    End Select
    aCounter = aCounter + 1
  Next
  
  UploadFile DestURL, FileName, FieldName
End Sub
 

 
'******************* upload - begin
'Upload file using input type=file
Sub UploadFile(DestURL, FileName, FieldName)
  'Boundary of fields.
  'Be sure this string is Not In the source file
  Const Boundary = "---------------------------0123456789012"
  
  Dim FileContents, FormData
  'Get source file As a binary data.
  FileContents = GetFile(FileName)
  
  'Build multipart/form-data document
  FormData = BuildFormData(FileContents, Boundary, FileName, FieldName)
  
  'Post the data To the destination URL
  IEPostBinaryRequest DestURL, FormData, Boundary
End Sub
 
'Build multipart/form-data document with file contents And header info
Function BuildFormData(FileContents, Boundary, FileName, FieldName)
  Dim FormData, Pre, Po
  Const ContentType = "application/upload"
  
  'The two parts around file contents In the multipart-form data.
  Pre = "--" + Boundary + vbCrLf + mpFields(FieldName, FileName, ContentType)
  Po = vbCrLf + "--" + Boundary + "--" + vbCrLf
  
  'Build form data using recordset binary field
  Const adLongVarBinary = 205
  Dim RS: Set RS = CreateObject("ADODB.Recordset")
  RS.Fields.Append "b", adLongVarBinary, Len(Pre) + LenB(FileContents) + Len(Po)
  RS.Open
  RS.AddNew
    Dim LenData
    'Convert Pre string value To a binary data
    LenData = Len(Pre)
    RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
    Pre = RS("b").GetChunk(LenData)
    RS("b") = ""
    
    'Convert Po string value To a binary data
    LenData = Len(Po)
    RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
    Po = RS("b").GetChunk(LenData)
    RS("b") = ""
    
    'Join Pre + FileContents + Po binary data
    RS("b").AppendChunk (Pre)
    RS("b").AppendChunk (FileContents)
    RS("b").AppendChunk (Po)
  RS.Update
  FormData = RS("b")
  RS.Close
  BuildFormData = FormData
End Function
 
'sends multipart/form-data To the URL using IE
Function IEPostBinaryRequest(URL, FormData, Boundary)
  'Create InternetExplorer
  Dim IE: Set IE = CreateObject("InternetExplorer.Application")
  
  'You can uncoment Next line To see form results
  'IE.Visible = True
   
  'Send the form data To URL As POST multipart/form-data request
  IE.Navigate URL, , , FormData, _
    "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf
 
  Do While IE.Busy
    Wait 1, "Upload To " & URL
  Loop
  
  'Get a result of the script which has received upload
  On Error Resume Next
  IEPostBinaryRequest = IE.Document.body.innerHTML
  IE.Quit
End Function
 
'Infrormations In form field header.
Function mpFields(FieldName, FileName, ContentType)
  Dim MPTemplate 'template For multipart header
  MPTemplate = "Content-Disposition: form-data; name=""{field}"";" + _
   " filename=""{file}""" + vbCrLf + _
   "Content-Type: {ct}" + vbCrLf + vbCrLf
  Dim Out
  Out = Replace(MPTemplate, "{field}", FieldName)
  Out = Replace(Out, "{file}", FileName)
  mpFields = Replace(Out, "{ct}", ContentType)
End Function
 

Sub Wait(Seconds, Message)
  On Error Resume Next
  CreateObject("wscript.shell").Popup Message, Seconds, "", 64
End Sub
 

'Returns file contents As a binary data
Function GetFile(FileName)
  Dim Stream: Set Stream = CreateObject("ADODB.Stream")
  Stream.Type = 1 'Binary
  Stream.Open
  Stream.LoadFromFile FileName
  GetFile = Stream.Read
  Stream.Close
End Function
 
'Converts OLE string To multibyte string
Function StringToMB(S)
  Dim I, B
  For I = 1 To Len(S)
    B = B & ChrB(Asc(Mid(S, I, 1)))
  Next
  StringToMB = B
End Function
'******************* upload - end

'******************* Support
'Basic script info
Sub InfoEcho()
  Dim Msg
  Msg = Msg + "Upload file using http And multipart/form-data" & vbCrLf
  Msg = Msg + "Copyright (C) 2001 Antonin Foller, PSTRUH Software" & vbCrLf
  Msg = Msg + "use" & vbCrLf
  Msg = Msg + "[cscript|wscript] fupload.vbs file url [fieldname]" & vbCrLf
  Msg = Msg + "  file ... Local file To upload" & vbCrLf
  Msg = Msg + "  url ... URL which can accept uploaded data" & vbCrLf
  Msg = Msg + "  fieldname ... Name of the source form field." & vbCrLf
  Msg = Msg + vbCrLf + CheckRequirements
  WScript.Echo Msg
  WScript.Quit
End Sub
 
'Checks If all of required objects are installed
Function CheckRequirements()
  Dim Msg
  Msg = "This script requires some objects installed To run properly." & vbCrLf
  Msg = Msg & CheckOneObject("ADODB.Recordset")
  Msg = Msg & CheckOneObject("ADODB.Stream")
  Msg = Msg & CheckOneObject("InternetExplorer.Application")
  CheckRequirements = Msg
'  MsgBox Msg
End Function
 
'Checks If the one object is installed.
Function CheckOneObject(oClass)
  Dim Msg
  On Error Resume Next
  CreateObject oClass
  If Err = 0 Then Msg = "OK" Else Msg = "Error:" & Err.Description
  CheckOneObject = oClass & " - " & Msg & vbCrLf
End Function
'******************* Support - end
 
Really hope some one is able to help, i just cant get my head around this to figure it out. Im so lost in the code
 
Hope this is ok to post here i searched and found nothing for vbscript at google
vbscript site:http://www.codeproject.com/Forums/
 
Once things are set i do have a htaccess file to try and restrict people to it by IP, i hope that should make it safe and ok
QuestionThrowing run time error while saving the record. PinmemberMember 786176324-Dec-12 2:11 
AnswerRe: Throwing run time error while saving the record. PinmemberEddy Vluggen25-Dec-12 3:03 
Questiongetting right string value from textbox with arabic text in vb6 PinmemberMember 970722123-Dec-12 0:44 
AnswerRe: getting right string value from textbox with arabic text in vb6 PinmemberEddy Vluggen23-Dec-12 14:17 
GeneralRe: getting right string value from textbox with arabic text in vb6 PinmemberMember 970722123-Dec-12 20:34 
GeneralRe: getting right string value from textbox with arabic text in vb6 PinmvpDave Kreskowiak24-Dec-12 5:06 
AnswerRe: getting right string value from textbox with arabic text in vb6 PinmemberEddy Vluggen25-Dec-12 8:26 
AnswerHelp, Win32_DefragAnalysis in VB6 code Pinmembernghia09t322-Dec-12 3:26 
GeneralRe: Help, Win32_DefragAnalysis in VB6 code PinmemberEddy Vluggen23-Dec-12 14:15 
QuestionListview vb6.0 PinmemberAinnop22-Dec-12 3:08 
AnswerRe: Listview vb6.0 PinmemberProgramFOX22-Dec-12 3:19 
Questionpuzzle game Pinmemberjasdeep788221-Dec-12 4:11 
AnswerRe: puzzle game PinmemberDavid Mujica21-Dec-12 4:33 
AnswerRe: puzzle game PinmvpRichard MacCutchan21-Dec-12 6:30 
QuestionTimer for Internet connection Pinmemberbolepks20-Dec-12 8:51 
AnswerRe: Timer for Internet connection PinmvpDave Kreskowiak20-Dec-12 9:46 
GeneralRe: Timer for Internet connection Pinmemberbolepks20-Dec-12 9:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 16 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid