Web Analytics Made Easy -
StatCounter ActiveX function to upload files from client - CodingForum

Announcement

Collapse
No announcement yet.

ActiveX function to upload files from client

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ActiveX function to upload files from client

    I want to upload one or several files from the client machine to the server machine. But I don't want the user to select the files. It is for an maintenance operation.

    I think I need to call ActiveX functions from JavaScript. I have used Scripting.FileSystemObject to manage the files on the client machine. But I can't find an ActiveX or an Application that would post the file or send it by another way to the server.

    Do you know such an ActiveX function ?

    Thanks,

    Joffrey

  • #2
    For an Intranet?
    Check out the Forum Search. It's the short path to getting great results from this forum.

    Comment


    • #3
      I didn't make this code, but I forget where I found it. So I'm not taking credit for it!

      I used this code in Outlook on my user's machines, and it worked quite nicely. I don't know if you can use the same idea in a WHS script:

      Code:
      '******************* treat this as a main method
      filename = "C:\temp_mail\tmp_msg.msg"
      
      'the first parameter is the webpage to post to
      'the second parameter is the filename
      'the third parameter is the variable to post the file to
      UploadFile "http://localhost/uploadprocess.php", filename, "file1"
      '******************* main - end
      
      '******************* upload - begin
      'Upload file using input type=file
      Sub UploadFile(DestURL As String, filename As String, _
        Optional ByVal FieldName As String = "File")
        Dim sFormData As String, d As String
        
        'Boundary of fields.
        'Be sure this string is Not In the source file
        Const Boundary As String = "---------------------------0123456789012"
      
        'Get source file As a string.
        sFormData = GetFile(filename)
        
        'Build source form with file contents
        d = "--" + Boundary + vbCrLf
        d = d + "Content-Disposition: form-data; name=""" + FieldName + """;"
        d = d + " filename=""" + filename + """" + vbCrLf
        d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
        d = d + sFormData
        d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf
        
        'Post the data To the destination URL
        IEPostStringRequest DestURL, d, Boundary
      End Sub
      
      'sends URL encoded form data To the URL using IE
      Sub IEPostStringRequest(URL As String, FormData As String, Boundary As String)
        'Create InternetExplorer
        Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")
        
        'You can uncoment Next line To see form results
        'WebBrowser.Visible = True
         
        'Send the form data To URL As POST request
        Dim bFormData() As Byte
        ReDim bFormData(Len(FormData) - 1)
        bFormData = StrConv(FormData, vbFromUnicode)
      
        WebBrowser.Navigate URL, , , bFormData, _
          "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf
      
        Do While WebBrowser.busy
      '    Sleep 100
          DoEvents
        Loop
        WebBrowser.Quit
      End Sub
      
      'read binary file As a string value
      Function GetFile(filename As String) As String
        Dim FileContents() As Byte, FileNumber As Integer
        ReDim FileContents(FileLen(filename) - 1)
        FileNumber = FreeFile
        Open filename For Binary As FileNumber
          Get FileNumber, , FileContents
        Close FileNumber
        GetFile = StrConv(FileContents, vbUnicode)
      End Function
      '******************* upload - end
      I don't know too much about WHS scripts, however, I do know they can be scheduled through Scheduled Tasks in Control Panel. This is in Windows of course. If you're looking to do this in a Unix system, you'd probably use the cron function. Your script would not be vb code of course!

      Hope that helps,
      Sadiq,

      Comment


      • #4
        Could u plz give me the location where I can find the translated version(in JScript)...?

        Comment


        • #5
          Who are you talking to Code Wizard?

          This is the only version of the code I've got, so I hope you're not talking to me!

          Sadiq.

          Comment


          • #6
            Thank you for your replies.

            I am afraid I was not clear enough. So here are some complements:

            I must launch the script from Internet Explorer. The user would come on a web page and click a button to say "I want to upload my datas to the server".

            The limit with IE is that you can't read a file on the machine from the script (for security). You need to use an ActiveX control.

            For Roy Sinclair: Yes, this is for an intranet. But it may be extended to use over Internet.

            For Sad: I think the script will work. But I will have to modify the part that reads the file and maybe more... Actually, I think the other part (post request) is just what I needed. I need to check first when I will get back to work tomorrow or Wednersday.

            Thanks again.

            Comment


            • #7
              If you plan to put it over the internet (unlike in intranet where environment is controlled), it is not advisable to use an ActiveX control as this poses a high security risk and by default activex is disabled.
              Glenn
              vBulletin Mods That Rock!

              Comment


              • #8
                I think the "ActiveX" controls are going to be your only bet for making this work which also mean you're locked to IE as the browser. For an Intranet you might want to consider the possibility of having users notify you via the web page but then use ordinary share level access to reach across the local network to the user's machines to retreive the files instead of trying to use the http protocol. For internet use, I'm going to assume you're thinking of company employees who are offsite. For those people you need to be talking to your network people about using the already established techniques for virtually extending your network to those machine so the same techniques used for the local machines will work for those users as well.
                Check out the Forum Search. It's the short path to getting great results from this forum.

                Comment

                Working...
                X