MadaraUchiha Posted December 16, 2013 Author Share Posted December 16, 2013 BUMP, once again ... :/ Link to comment Share on other sites More sharing options...
Developers Jos Posted December 16, 2013 Developers Share Posted December 16, 2013 You are becoming a little impatient here in this thread. Please read our forum rules and don't bump threads within 24 hours. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 16, 2013 Author Share Posted December 16, 2013 Hm, sorry for that, but I am really overwhelemed with this... I tried everything... And always teh file is corrupted... I tried FileOpen with param 0 and param 16, still corrupted. Also tried Binary and BinaryToString. I can't understand why the file is corrupted and it won't just upload a valid file? :/ Link to comment Share on other sites More sharing options...
Developers Jos Posted December 16, 2013 Developers Share Posted December 16, 2013 Maybe you have still have a PHP issue? Shouldn't you be opening the file in binary mode? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 16, 2013 Author Share Posted December 16, 2013 Maybe you have still have a PHP issue? Shouldn't you be opening the file in binary mode? Jos You mean on PHP side? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 16, 2013 Developers Share Posted December 16, 2013 (edited) You mean on PHP side? Stop asking and start trying/researching. Edited December 16, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Solution MadaraUchiha Posted December 16, 2013 Author Solution Share Posted December 16, 2013 Finally solved it! Just for everyone else, if someone will ever need this: If you like to upload a file to your webserver, without using FTP, then just use this AutoIt script: $File = @ScriptDir & "\test.jpg" $sHost = "www.yourserver.com" $sFormAction = "/postdata.php" $hfile = FileOpen($File, 16) $sFileTypeName = StringRegExpReplace($File, '^.*\\', '') While 1 $data = FileRead($hfile, 500000) ;500000 = 1?? If @error Then ExitLoop Global $Data2 = StringTrimLeft($data,2) SendPost() WEnd Func SendPost() $oRequest = ObjCreate('WinHttp.WinHttpRequest.5.1') $oRequest.Open('POST', 'http://' & $sHost & $sFormAction, 0) $oRequest.SetRequestHeader('User-Agent', 'Mozilla/4.0 (Windows XP 5.1)') $oRequest.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded') $oRequest.SetRequestHeader('Host', $sHost) $oRequest.Send('filename=' & $sFileTypeName & '&data=' & $Data2) $sData = $oRequest.ResponseText MsgBox(0, 'Data', $sData) EndFunc And your PHP Script should look like this: <?php $fileName = $_POST['filename']; $binaryData = $_POST['data']; $fh = fopen("./$fileName", 'a+b'); fwrite($fh, pack("H*" , $binaryData)); fclose($fh); ?> Link to comment Share on other sites More sharing options...
AutID Posted December 17, 2013 Share Posted December 17, 2013 Finally solved it! Just for everyone else, if someone will ever need this: If you like to upload a file to your webserver, without using FTP, then just use this AutoIt script: $File = @ScriptDir & "\test.jpg" $sHost = "www.yourserver.com" $sFormAction = "/postdata.php" $hfile = FileOpen($File, 16) $sFileTypeName = StringRegExpReplace($File, '^.*\\', '') While 1 $data = FileRead($hfile, 500000) ;500000 = 1?? If @error Then ExitLoop Global $Data2 = StringTrimLeft($data,2) SendPost() WEnd Func SendPost() $oRequest = ObjCreate('WinHttp.WinHttpRequest.5.1') $oRequest.Open('POST', 'http://' & $sHost & $sFormAction, 0) $oRequest.SetRequestHeader('User-Agent', 'Mozilla/4.0 (Windows XP 5.1)') $oRequest.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded') $oRequest.SetRequestHeader('Host', $sHost) $oRequest.Send('filename=' & $sFileTypeName & '&data=' & $Data2) $sData = $oRequest.ResponseText MsgBox(0, 'Data', $sData) EndFunc And your PHP Script should look like this: <?php $fileName = $_POST['filename']; $binaryData = $_POST['data']; $fh = fopen("./$fileName", 'a+b'); fwrite($fh, pack("H*" , $binaryData)); fclose($fh); ?> Glad you found a solution. That is autoit scripting but not pure autoit. Your script will just crash in case your winhttp object returns an error. But since this thread is marked as solved then there is not much more to say https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 17, 2013 Author Share Posted December 17, 2013 Its marked as solved but if you have a better solution please tell me:) zenmark22 1 Link to comment Share on other sites More sharing options...
zenmark22 Posted December 25, 2022 Share Posted December 25, 2022 Hi @MadaraUchiha Your code works, but only if you run it once. if you don't delete the image from the server and run the code a second time, it won't work anymore. 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