PHPWarner Posted December 20, 2009 Share Posted December 20, 2009 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 More sharing options...
Mat Posted December 20, 2009 Share Posted December 20, 2009 $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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
PHPWarner Posted December 20, 2009 Author Share Posted December 20, 2009 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 More sharing options...
Mat Posted December 20, 2009 Share Posted December 20, 2009 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
PHPWarner Posted December 20, 2009 Author Share Posted December 20, 2009 (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 December 20, 2009 by PHPWarner Link to comment Share on other sites More sharing options...
Mat Posted December 20, 2009 Share Posted December 20, 2009 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
PHPWarner Posted December 20, 2009 Author Share Posted December 20, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now