Jump to content

Php and autoit combination


Drya
 Share

Recommended Posts

Hello,

i created a upload script in php, this works with a <input type="file" name="file" id="file">.

Now i want to create a autoitscript wich would allow me to upload files using the php script.

i was thinking of creating a socket and make a connection to my server and send the file,

but is the file stored in the header? or something else?

i dont know where to start and i was hoping that someone could help me.

Best regards,

Link to comment
Share on other sites

What i want to do is:

Create a autoit script;

make the script connect to: www.mydomain.com:80 \\ so yes i connect to my server at port 80.

create a costum header so it makes my server think i want to upload a file using upload.php...

so i want to know what the header should look like, where i should put the file etc... etc.. etc..

Does anyone know more about this?

Edited by Drya
Link to comment
Share on other sites

Is there really no one who can help me?

Quit being wrongheaded and whiny.

You have a web application (php upload script) that you want to automate. You've been told what to look at in order to accomplish the task.

It has been done. You can do it, too. Go forth, and try.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

  • 4 weeks later...

Actually this is a good question, for example.. I am trying to make a AutoIT program automatically upload a file called CharacterProfiler.lua to "uploader.php" but the problem is the IE.au3 can't automatically fill out the upload field value, so the other way around is to make the AutoIT upload using another way, like sending header data to the .php file instead (submitting the file trough the script and not depend on Internet Explorer).

I would love if someone could help me out a bit here.. :)

FTP is not really actual since the .php have to parse the file and it's not safe to access a FTP with this method when the program will be used on 30 peoples machines, so it will keep their data up to date with the server data. If 30 programs try to access the FTP to upload it will ban me for 30 minutes because of flooding, then no one will be able to use it. ;)

Edited by VRor
Link to comment
Share on other sites

Im sick of people always saying "use ie.au3", when the OP specifically says that he DOESNT want to use it.

Flyboz, if you READ, he says he DOESNT want to use IE.

Anyway, Ive tried this a few times, I couldnt get it working. But heres a vbscript example.

It uses winhttprequest object. Ive been able to do pretty much anything with that object, ive been using it for years.

Just havnt figured out how to send a file over.

If I could get a link to the upload.php or whatnot, I can try helping.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

http://vlacula.no-ip.com/wowroster/update.php

What basically has to happen is, there is a file that is saved in a specific folder. I already have a function that gets the installation directory from the registry and the sub directories parsing a text file, so let's (example) say the file path the function returns is:

C:\WoW\WTF\Accounts\Myaccount\SavedVariables\CharacterProfiler.lua

Now, that file has to be somehow uploaded via the update.php file trough a function, using IE.au3 is not a option as the IE has security build in that prevents input fields that are type=file to be automated in any other way (only manually). Since different computers, browsers and such got different ways of handling the standard Send() function using that way to tab trough fields like:

Send("{TAB 15}") ; tab to the "Browse" button

Send("{SPACE}") ; space to open it

Send("C:\WoW\WTF\Accounts\Myaccount\SavedVariables\CharacterProfiler.lua") ; the file path

Send("{ENTER}") ; submit browse file dialog

.. this is not a good solution at all. Most get errors and script halts up and such, so using some other method to submit the header data (file and password field) is much safer and easier. Like in PHP you can use this to make the PHP to submit a form for you:

function do_post_request($url, $data, $optional_headers = null)

{

$params = array('http' => array(

'method' => 'POST',

'content' => $data

));

if ($optional_headers !== null) {

$params['http']['header'] = $optional_headers;

}

$ctx = stream_context_create($params);

$fp = @fopen($url, 'rb', false, $ctx);

if (!$fp) {

throw new Exception("Problem with $url, $php_errormsg");

}

$response = @stream_get_contents($fp);

if ($response === false) {

throw new Exception("Problem reading data from $url, $php_errormsg");

}

return $response;

}

$data = array( 'field'=>$fieldvalue,

'field_stuff'=>$more_values,

'okayitsenough'=>$avalue);

do_post_request("http://www.domain.com/update.php", http_build_query($data));

(I am aware of that the PHP example won't upload a file, only submit text fields. :))

Getting something similar in AutoIT that also supported uploading a file would be really handy!

Link to comment
Share on other sites

hehe just because i LOVE WOW and WOW addon scripting i'll have to help u on that one :)

how big is that .lua file ?!

if it's a matter of KBs [as should be] you can use an OBJ to connect and send it.... i'll be more precise when i'll know the file size...

_____________

Edited by Armand

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

hehe just because i LOVE WOW and WOW addon scripting i'll have to help u on that one :)

how big is that .lua file ?!

if it's a matter of KBs [as should be] you can use an OBJ to connect and send it.... i'll be more precise when i'll know the file size...

The file size will change as more data is stored, right now it's on 650 KB (666 196 bytes) - hehe

---

The thing is, we got a guild addon package. People download a EXE (autoit) and it keeps some guild addons up to date, when ever I update them and upload they will get them downloaded and installed when they use the EXE to launch their game. I recently added a profiler, to help track professions but in order to get the data automatically uploaded to the PHP file is a small challenge for me now since I have never used AutoIT to submit a file before..

I am trying to keep the script as much automated as possible, so what is left for the clients (users) to do is use the program and game starts. The background events that handle files, upload, download and such are kept hidden to not disturb or cause confusion. - Hope you understand my situation now. ;)

The lua is plain text, so we won't need any special encoding (it's not a picture or video, e.g.) :D

Edited by VRor
Link to comment
Share on other sites

oky... here it is for small file sizes, [works as posting text into php]

_____________

;Put the name of the accepting PHP "input"
$inputN = "FileUpload"

;Get file content.
$FileH = FileOpen("C:\WoW\WTF\Accounts\Myaccount\SavedVariables\CharacterProfiler.lua", 0)
$FileContent = FileRead($FileH)
FileClose($FileH)

;Set the posting var:
$PostContent = $inputN&"="&$FileContent

;Write down headers:
Dim $MyHeaders[3][2]
$MyHeaders[0][0] = "User-Agent"
$MyHeaders[0][1] = "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"
$MyHeaders[1][0] = "Cache-Control"
$MyHeaders[1][1] = "no-cache"
$MyHeaders[2][0] = "Content-Type"
$MyHeaders[2][1] = "text/html; charset=iso-8859-1"
;.... whatever u need....

;Use my improvised UDF for the communication:
CommunicateWithPHPSite( _
    "http://vlacula.no-ip.com/wowroster/update.php", _
    "MSXML2.ServerXMLHTTP", _
    "POST", _
    False, _
    $MyHeaders, _
    $PostContent _
)
Func CommunicateWithPHPSite($sWebAddress, $oObject, $sMethod, $bSynchro, $aHeaders, $sPostVar)
    Global $UploadingOBJ = ObjCreate("MSXML2.ServerXMLHTTP")
    $UploadingOBJ.Open("POST", $sWebAddress, False)
    For $i = 0 To UBound($aHeaders)-1
        $UploadingOBJ.setRequestHeader($aHeaders[$i][0], $aHeaders[$i][1])
    Next
    $UploadingOBJ.setRequestHeader("Content-Length", StringLen($sPostVar))
    $UploadingOBJ.Send($sPostVar)
EndFunc

Please note, i've commented most of the script so that you'll be able to use it as you see fit... it might not work as is... but i think it'll be easier to move forth from here...

___________________________

TIP: have a look at these:

SK's-Dkp_Listings:

http://www.curse.com/downloads/details/2398/

SK's-Dkp_System Updater:

http://www.curse.com/downloads/details/2398/

these hold that exact thing you need to do...

Edited by Armand

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

I did a submit using Live HTTP Headers to check the header input on the upload, and it looks like this:

http://vlacula.no-ip.com/wowroster/update.php

POST /wowroster/update.php HTTP/1.1

Host: vlacula.no-ip.com

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b4) Gecko/2008030714 Firefox/3.0b4 Creative ZENcast v2.00.07

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://vlacula.no-ip.com/wowroster/update.php

Content-Type: multipart/form-data; boundary=---------------------------41184676334

Content-Length: 666518

-----------------------------41184676334

Content-Disposition: form-data; name="CharacterProfiler"; filename="CharacterProfiler.lua"

Content-Type: application/octet-stream

<FILE CONTENTS HERE>

-----------------------------41184676334

Content-Disposition: form-data; name="password"

<PASSWORD FIELD VALUE HERE>

-----------------------------41184676334--

I've been thinking, can't we somehow put that data in the:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$ResolveTimeout = 5000

$ConnectTimeout = 5000

$SendTimeout = 5000

$ReceiveTimeout = 5000

$oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")

$oHttpRequest.Open ("POST", "http://vlacula.no-ip.com/wowroster/update.php",True)

$oHttpRequest.setRequestHeader ("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b4) Gecko/2008030714 Firefox/3.0b4 Creative ZENcast v2.00.07")

$oHttpRequest.setRequestHeader ("Keep-Alive", "300")

$oHttpRequest.setRequestHeader ("Connection", "keep-alive")

$oHttpRequest.setRequestHeader ("Referer", "http://vlacula.no-ip.com/wowroster/update.php")

$oHttpRequest.setRequestHeader (...)

$oHttpRequest.Send()

..where $oHttpRequest.setRequestHeader (...) is the header data from above? I am sure this didn't work at least:

$oHttpRequest.setRequestHeader  ("Content-Type", 'multipart/form-data; boundary=---------------------------41184676334'&@CRLF&'Content-Length: 666518'&@CRLF&'-----------------------------41184676334'&@CRLF&'Content-Disposition: form-data; name="CharacterProfiler"; filename="CharacterProfiler.lua"'&@CRLF&''&@CRLF&'Content-Type: application/octet-stream'&@CRLF&@CRLF&@CRLF&FileRead($file)&@CRLF&@CRLF&'-----------------------------41184676334')
$oHttpRequest.setRequestHeader  ("Content-Disposition", 'form-data; name="password"'&@CRLF&@CRLF&'steam'&@CRLF&'-----------------------------41184676334--')

But you get the idea.. think it could be done? Tried to play a bit with the code and codes I found other places but still can't make it work as it should. Also the SK's-Dkp_System updater is based on a "GET" function so not quite the same as POST. :)

Edited by VRor
Link to comment
Share on other sites

well... i can't seem to find what's the issue with using the stupid UDF i've made ya... it should work just the same... just set the array headers and it all should run accordingly...

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

well... i can't seem to find what's the issue with using the stupid UDF i've made ya... it should work just the same... just set the array headers and it all should run accordingly...

I might be using a older version of AutoIT, lol.. will update it when I come home again to test it out then. :)

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...