MadaraUchiha Posted December 14, 2013 Share Posted December 14, 2013 (edited) Hey, I liek to upload a image file to my webserver without using FTP. I tried this already ( '?do=embed' frameborder='0' data-embedContent>> ), it started without errors, also has shown me the msgbox with the headers, but the file doesn't appear on the server. Why it does not upload? I am looking for a method to uplaod a file to my webserver, if possible very clean, without defining the headers etc, just a short pure Winhttp function to upload a file :/ Edited December 14, 2013 by MadaraUchiha Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 I've seen multiple samples here on the forum but most of didn't work for me, and nearly all are using a HTML form to fill out. Isn't it possible to send binary data to a PHP file? I am looking for a win http (_WinHttpSendRequest or _WinHttpWriteData??) solution. TCP and FTP is not an option for me. Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 Bump. Link to comment Share on other sites More sharing options...
trancexx Posted December 15, 2013 Share Posted December 15, 2013 And your php page looks like? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) My PHP Script looks like this: <?php move_uploaded_file($_FILES[$_GET["datei"]]['tmp_name'], $_GET["datei"]); ?> And the AutoIt script looks like this: #include <Inet.au3> $Pfad = "C:\Users\Domi\Desktop\Test.png" _InetGetSource("http://[censored]/upload.php?datei="& $Pfad & "") But nothing happens. When I run the script, I get no errors but the file doesn't appear on my webserver? Edited December 15, 2013 by MadaraUchiha Link to comment Share on other sites More sharing options...
trancexx Posted December 15, 2013 Share Posted December 15, 2013 Either learn php or find some example of php code which processes input correctly.I believe php's documentation gives an example of how to do it correctly. Your code if fucking ridiculous. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 So it is the PHP Part which is not correct? Or is it the Autoit part? Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 Hm, ok got a working PHP script... <? $upload = $_GET["upload"]; if ($upload == "now") { $path1 = "uploads/"; $path="$path1".$_FILES['ufile']['name']; if($ufile !=none) { if(copy($_FILES['ufile']['tmp_name'], $path)) { echo "Success!<BR/>"; echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=uploads/\">"; } else { echo "<font color=red><b>Error!</b></font>"; } } } else { ?> <table width="250" border="0" align="left" cellpadding="0" cellspacing="1"> <tr> <form action="?upload=now" method="post" enctype="multipart/form-data"> <td> <table border="0" cellpadding="3" cellspacing="1"> <tr> <td>Select file <input name="ufile" type="file" id="ufile" /></td> </tr> <tr> <td align="left"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> <a href="uploads">View Uploads</a> <? } ?> But i like to upload: 1) With WinHTTP.au3 2) Using POST instead of GET 3) Without a form. How? ;o Link to comment Share on other sites More sharing options...
trancexx Posted December 15, 2013 Share Posted December 15, 2013 Remove form part from your page and do something like this:#include "WinHttp.au3" Global Const $sFileToUpload = @ScriptFullPath ;<- Set correct file location here (current choice uploads this script) Global Const $sAddress = "http://whatever.org/zz.php" ;<- Set correct address here ; Form to fill (page doesn't have transparent form) Local $sForm = _ '<form action="' & $sAddress & '?upload=now"" method="post" enctype="multipart/form-data">' & _ ' <input type="file" name="ufile"/>' & _ ; '</form>' ; Initialize and get session handle $hOpen = _WinHttpOpen() $hConnect = $sForm ; will pass form as string so this is for coding correctness because $hConnect goes in byref ; Fill form $sHTML = _WinHttpSimpleFormFill($hConnect, $hOpen, _ Default, _ "name:ufile", $sFileToUpload) If @error Then MsgBox(4096, "Error", "Error number = " & @error) Else MsgBox(64, "Success", "Result: " & @CRLF & $sHTML) EndIf ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) Remove form part from your page and do something like this: #include "WinHttp.au3" Global Const $sFileToUpload = @ScriptFullPath ;<- Set correct file location here (current choice uploads this script) Global Const $sAddress = "http://whatever.org/zz.php" ;<- Set correct address here ; Form to fill (page doesn't have transparent form) Local $sForm = _ '<form action="' & $sAddress & '?upload=now"" method="post" enctype="multipart/form-data">' & _ ' <input type="file" name="ufile"/>' & _ ; '</form>' ; Initialize and get session handle $hOpen = _WinHttpOpen() $hConnect = $sForm ; will pass form as string so this is for coding correctness because $hConnect goes in byref ; Fill form $sHTML = _WinHttpSimpleFormFill($hConnect, $hOpen, _ Default, _ "name:ufile", $sFileToUpload) If @error Then MsgBox(4096, "Error", "Error number = " & @error) Else MsgBox(64, "Success", "Result: " & @CRLF & $sHTML) EndIf ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Tried it now. Doesn't work: My PHP Script: <? $upload = $_GET["upload"]; if ($upload == "now") { $path1 = "uploads/"; $path="$path1".$_FILES['ufile']['name']; if($ufile !=none) { if(copy($_FILES['ufile']['tmp_name'], $path)) { echo "Success!<BR/>"; echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=uploads/\">"; } else { echo "<font color=red><b>Error!</b></font>"; } } } ?> AutoIt code: #include "WinHttp.au3" Global Const $sFileToUpload = @ScriptFullPath ;<- Set correct file location here (current choice uploads this script) Global Const $sAddress = "http://whatever.org/zz.php" ;<- Set correct address here ; Form to fill (page doesn't have transparent form) Local $sForm = _ '<form action="' & $sAddress & '?upload=now"" method="post" enctype="multipart/form-data">' & _ ' <input type="file" name="ufile"/>' & _ ; '</form>' ; Initialize and get session handle $hOpen = _WinHttpOpen() $hConnect = $sForm ; will pass form as string so this is for coding correctness because $hConnect goes in byref ; Fill form $sHTML = _WinHttpSimpleFormFill($hConnect, $hOpen, _ Default, _ "name:ufile", $sFileToUpload) If @error Then MsgBox(4096, "Error", "Error number = " & @error) Else MsgBox(64, "Success", "Result: " & @CRLF & $sHTML) EndIf ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Error message: Whats wrong? O_o Edited December 15, 2013 by MadaraUchiha Link to comment Share on other sites More sharing options...
Developers Jos Posted December 15, 2013 Developers Share Posted December 15, 2013 Remove the "else {" from the last line. 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 15, 2013 Author Share Posted December 15, 2013 Remove the "else {" from the last line. Did that, got another error, updated my post ... Link to comment Share on other sites More sharing options...
trancexx Posted December 15, 2013 Share Posted December 15, 2013 Whats wrong? O_oYour server settings? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 Hm, how can I just upload to the main directory? Link to comment Share on other sites More sharing options...
trancexx Posted December 15, 2013 Share Posted December 15, 2013 You ask wrong questions. You ask dumb questions....Google the error you got. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) I did... I tried changing the path, same error... I really wonder why there is no simple fileupload function available for WinHttp.au3 Edited December 15, 2013 by MadaraUchiha Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 Ok, look. I made a sample to upload a String using Post method to my php script and echo it in a txt file: #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Initialize and get session handle Global $hOpen = _WinHttpOpen() ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen,InputBox('Enter Host','Enter your Host without http:// , use www instead.' & @LF & "Sample www.myserver.com also don't put /Test.Php at the end!")) ; Simple-request it... MsgBox(64, "Result", _WinHttpSimpleRequest($hConnect, "POST", "/Test.php", Default, "Data=" & InputBox('String','String u like to send to the server'))) ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) PHP: <?php if( $_POST["Data"]) { file_put_contents('Result.txt',$_POST['Data']); echo "Uploaded."; exit(); } ?> That works fine. Now I tried to uplaod a file using FileRead(FileOpen(@ScriptDir & '\ufile.png',16)) instead of the string i enter in the inputbox. It now uploads the bytes to the txt file... but I need to upload, so it will appear as image on the sever? I am close to done, just this little thingy I need to fix, but how? Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 15, 2013 Author Share Posted December 15, 2013 okay... Got it now so far that the file appears, but it seems corrupted. The bytes of the file which arrive on the server is twice times large than the original file... #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Initialize and get session handle Global $hOpen = _WinHttpOpen() ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen,InputBox('Enter Host','Enter your Host without http:// , use www instead.' & @LF & "Sample www.myserver.com also don't put /Test.Php at the end!")) ; Simple-request it... MsgBox(0,'Response',_WinHttpSimpleRequest($hConnect, "POST", "/Test.php", Default, "data=" & (FileRead(FileOpen(@ScriptDir & '\ufile.png',16))))) ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) <?php $Bytes = $_POST["data"]; $fp = fopen('data.png', 'w+'); fwrite($fp, $Bytes); fclose($fp); echo "Bien :)"; exit(); ?> Link to comment Share on other sites More sharing options...
AutID Posted December 16, 2013 Share Posted December 16, 2013 (edited) With those php code problems i would use an other server instead of mine. I can provide you an example of an image upload on a working server if that is what you need so you can go on with your life P.S and try declaring fileread and fileopen functions outside the _WinHttpSimpleRequest Edited December 16, 2013 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
MadaraUchiha Posted December 16, 2013 Author Share Posted December 16, 2013 Yes, I would really like to see your example. Can u pm me? 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