Jump to content

Uploading Image To A Php Page


Adele
 Share

Go to solution Solved by SmOke_N,

Recommended Posts

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 by Adele
Link to comment
Share on other sites

  • Moderators

base64 it before upload and then unpack from php side.

Edited 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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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.

kodevreni_1422396306__ss.png

Edited by Adele
Link to comment
Share on other sites

  • Moderators
  • Solution

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

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