Sign in to follow this  
Followers 0
PHPWarner

Explorer picture upload

7 posts in this topic

Hello,

That is my first time for meet with AutoIt but I am very pleased to use it. Thanks for developers for AutoIt.

My question is,

How can I upload any picture to the any web site.

I am using this code:

#include <IE.au3>
$oIE = _IECreate ("http://www.site.com/upload_file.php")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetObjByName ($oForm, "photo")
_IEFormElementSetValue ($oQuery, "C:\2009122147.jpg")

$oButton = _IEFormElementGetObjByName ($oForm, "submit")
_IEAction($oButton, "click")

It should be upload "C:\2009122147.jpg" to the web site. But, I guess <input type="file"> does not accept direct values. So I am very please for your advice.

Thanks now.

Share this post


Link to post
Share on other sites



$IE_Object.document.getElementById("filefield").focus()
ControlSend ($IE_Parent, "", GUICtrlGetHandle ($IE_Ctrl), $sFile, 1)

Thats the solution I'm using. Where:

$IE_Parent = GUICreate ("Hidden IE window", 1000, 800)
$IE_Object = ObjCreate ("Shell.explorer.2")
$IE_Ctrl = GUICtrlCreateObj ($IE_Object, 2, 2, 1000, 800)

There are already some threads on this, but that is sadly the only way that works. Using _IECreate, you can use PropertyGet to get the handle to the control.

"hwnd" || Retrieves the handle of the Internet Explorer main window. Can be used in most AutoIt Win* functions.

Mat

Share this post


Link to post
Share on other sites

So it should be like that?

#include <IE.au3>
$oIE = _IECreate ("http://www.site.com/upload_file.php")
$oForm = _IEFormGetCollection ($oIE, 0)

$IE_Parent = GUICreate ("Hidden IE window", 1000, 800)
$IE_Object = ObjCreate ("Shell.explorer.2")
$IE_Ctrl = GUICtrlCreateObj ($IE_Object, 2, 2, 1000, 800)

$sFile = 'C:\2009122147.jpg'
$IE_Object.document.getElementById("photo").focus()
ControlSend ($IE_Parent, "", GUICtrlGetHandle ($IE_Ctrl), $sFile, 1)

$oButton = _IEFormElementGetObjByName ($oForm, "submit")
_IEAction($oButton, "click")

$oButton = _IEFormElementGetObjByName ($oForm, "submit")
_IEAction($oButton, "click")

But it didn't work. I guess I did a mistake on codes.

Share this post


Link to post
Share on other sites

My code was for creating an embedded object, so no. This example from PsaltyDs is probably more like it.

#include <IE.au3>

Global $sCAB, $new_page, $tmp_page, $oForm, $oInput

_IEErrorHandlerDeRegister()

$sCAB = "C:\Work\Irisys\SDI_files\SmartlaneCAB.CAB"
$new_page = "http://10.131.180.109/RemoteAdmin/updateform.html"
$tmp_page = _IECreate($new_page)
_IELoadWait($tmp_page, 1000, 15000)
$oForm = _IEFormGetObjByName($tmp_page, "configForm")
$oInput = _IEFormElementGetObjByName($oForm, "cabfile")
_IEAction($oInput, "focus")
$hIE = _IEPropertyGet($tmp_page, "hwnd")
ControlSend($hIE, "", "", $sCAB)
_IEFormSubmit($oForm)

Its a similar idea.

Mat

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for your helps. Everything works fine until this code.

$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "", $sCAB)

I don't understand hwnd meaning?

Thanks.

Edited by PHPWarner

Share this post


Link to post
Share on other sites

HWnd is just short for Handle WiNDow, and returns a handle that can be used to manipulate the window. That handle is then used in order to send data to the window, the data being $sCAB.

I don't know how well that explains it...

Mat

Share this post


Link to post
Share on other sites

Okay my final codes are below, but uploading image still does not work, maybe I've made a mistake. Could you please check it for me?

#include <IE.au3>
$oIE = _IECreate ("http://www.site.com/upload_file.php")
$oForm = _IEFormGetCollection ($oIE, 0)

$iFile = "C:\4287_2009121527.jpg"

$oInput = _IEFormElementGetObjByName($oForm, "photo")
_IEAction($oInput, "focus")
$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "", $iFile)

$oButton = _IEFormElementGetObjByName ($oForm, "submit")
_IEAction($oButton, "click")

It is running focus but it didn't select image file and upload ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0