
VB ActiveX to upload a file using HTTP Post
Well if you are using the cpshost.dll in the following manner in http:
<form
action="http://MyNTServer/scripts/cpshost.dll?PUBLISH?http://MyNTServer/MyTe
stProject/ProcFile.asp"
encType="multipart/form-data" id="form2" method="post" name="form2"
<input type="hidden" name="TargetURL"
value="http://MyNTServer/MyTestProject/upload/<%=varPath%>">
....
</form>
then you have to prepare the whole thing in the following way:
- Be sure your upload directory has the correct rights (writable, no
execution, not readable, ...) on directory and file basis.
- You have to add an entry inside the registry that allows anonymous logins
at you server, otherwise the upload will always fail. Adding this entry is
the key (I attach the Knowledge Base article in this RE).
Be aware: Allowing anonymous logins to your server may harm your system if
you are lazy setting the access rights in IIS an at the file system. If you
allow anonymous logins an there is an directory with write an execute
permission in IIS and the file system anybody can put an executable on your
system and start it !!!...
Attched: The Knowledge Base article: Article ID: Q179566
===============================================
For Microsoft Internet Information Server (IIS) 3.0:
1. Remove the authentication code from any .asp files involved with
the upload process (for example, upload*.asp, repost.asp).
2. Set the TargetURL variable to a directory that IUSR_<machinename>
has write access to.
3. Start In the .asp files involved with the upload process and open the
following location in the registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\WebPost\Acceptors\CPSHost
4. Create a new REG_DWORD value named "AllowAnonymous" and set the value
to "1" (both without the quotation marks).
5. Reboot the computer.
For Microsoft Internet Information Server (IIS) 4.0:
1. In the Microsoft Management Console (MMC), create a virtual root with
write access permissions (as designated in the MMC).
2. Make sure that the Allow Anonymous option is enabled for the virtual
root created, for the /Scripts directory, and for the Web root.
3. In the .asp files involved with the upload process, remove the
authentication code.
4. Set the TargetURL variable in the Postinfo.asp and Upload.asp files
to a directory that IUSR_<machinename> has write access to.
5. Start Regedt32.exe, and open the following location in the registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\WebPost\Acceptors\CPSHost
6. Create a new REG_DWORD value named "AllowAnonymous" and set the value
to "1" (both without the quotation marks).
7. Reboot the computer.
Quote:
> Hello,
> I would like to make an VB ActiveX to upload file from IE to my server,
> using HTTP POST upload. I have got the following example but it is not
> working. Does anybody know how to do something like that? How to get
> XMLHTTP26?
> Many thanks,
> Sebastien
> Option Explicit
> 'This code uploads a file to an ASP script using http post
> 'You need to add a reference to Microsoft XML, V26 to the project.
> 'Get this from http://www.microsoft.com/xml
> Private Sub cmdSubmit_Click()
> Dim strText As String
> Dim strBody As String
> Dim strFileName As String
> Dim oHttp As XMLHTTP26
> 'make use of the XMLHTTPRequest object contained in msxml.dll
> Set oHttp = New XMLHTTP26
> 'enter your data
> strText = InputBox("Text:", "Upload a file", "<h1>Test2</h1>")
> strFileName = InputBox("File Name:", "Upload a file", "dummy.htm")
> 'fire of an http request
> oHttp.open "POST", "http://www.../upload.asp", False
> oHttp.setRequestHeader "Content-Type", "multipart/form-data,
> boundary=AaB03x"
> 'assemble the body. send one field and one file
> strBody = _
> "--AaB03x" & vbCrLf & _
> "content-disposition: form-data; name=""field1""" & vbCrLf & vbCrLf & _
> "test field" & vbCrLf & _
> "--AaB03x" & vbCrLf & _
> "content-disposition: form-data; name=""xyz""; filename=""" &
strFileName
> & """" & vbCrLf & _
> "Content-Type: text/plain" & vbCrLf & vbCrLf & _
> strText & vbCrLf & _
> "--AaB03x--"
> 'send it
> oHttp.send strBody
> 'check the feedback
> Debug.Print oHttp.responseText
> End Sub