Adele Posted January 27, 2015 Share Posted January 27, 2015 (edited) Hi everybody. I want to upload a image file to a php page. I tried base64 method but I had problem. Then I wanted to try WinHTTP method but there is problem again. The codes are below. What is the problem? Or is there a different method to upload image without using form and IE? I researched a lot of topics here but I couldn't find a working a thing. Thank you in advance. AutoIt Codes: #include <ScreenCapture.au3> $sScreenShotFile = @TempDir & "\ScreenShot.png" $hScreenShot = _ScreenCapture_Capture($sScreenShotFile) $hfile = FileOpen($sScreenShotFile, 16) $sData = FileRead($hfile) $oRequest = ObjCreate('WinHttp.WinHttpRequest.5.1') $oRequest.Open('POST', 'http://site.com/index.php', 0) $oRequest.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded') $oRequest.Send('screenshot=' & $sData) PHP Codes: <?php if(isset($_POST['screenshot']) && !empty($_POST['screenshot'])){ $file = fopen(dirname(__FILE__) . "/screenshot.png", "w+b"); fwrite($file, pack("H*" ,$_POST['screenshot'])); fclose($file); } ?> The problem is that; the image uploads but their contents aren't same. I guess there is a problem on binary coding. Edited January 27, 2015 by Adele Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 27, 2015 Moderators Share Posted January 27, 2015 (edited) base64 it before upload and then unpack from php side. Edited January 27, 2015 by SmOke_N spelling Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
mesale0077 Posted January 27, 2015 Share Posted January 27, 2015 look to site http://stackoverflow.com/questions/11511511/how-to-save-a-png-image-server-side-from-a-base64-data-string or http://stackoverflow.com/questions/15140063/extract-a-file-from-a-zip-string ı dont know php Link to comment Share on other sites More sharing options...
Adele Posted January 27, 2015 Author Share Posted January 27, 2015 base64 it before upload and then unpack from php side. No, I'm using now with upper codes binary method. I've tried base64 method but I had problem. Sorry for my English . Link to comment Share on other sites More sharing options...
guinness Posted January 27, 2015 Share Posted January 27, 2015 You could look at trancexx's WinHTTP UDF. It's pretty awesome. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Adele Posted January 27, 2015 Author Share Posted January 27, 2015 (edited) You could look at trancexx's WinHTTP UDF. It's pretty awesome. I've tried and unfortunately the result is the same. I open the file being binary with this code: $hfile = FileOpen($sScreenShotFile, 16) After send the binary information, then I try to convert taken binary codes to string and save to a file on php. $file = fopen(dirname(__FILE__) . "/screenshot.png", "w+b"); fwrite($file, pack("H*" ,$_POST['screenshot'])); The codes run and are created but there is a problem. The file isn't transmitted correctly. Edited January 27, 2015 by Adele Link to comment Share on other sites More sharing options...
Moderators Solution SmOke_N Posted January 27, 2015 Moderators Solution Share Posted January 27, 2015 I remember I ran into an issue with base64 when I had done something very similar, I believe it was the equal signs but can't remember (been a couple of years). I think I did base64+StringToHex to pass it. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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