Jump to content

Explorer picture upload


 Share

Recommended Posts

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.

Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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 ;)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...