mardi 27 janvier 2015

Uploading Image With AutoIt To A Php Page


Vote count:

0




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://ift.tt/1dt4zI4', 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.


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");


The codes run and are created but there is a problem. The file isn't transmitted correctly. http://ift.tt/1D5H3xs



asked 1 min ago







Uploading Image With AutoIt To A Php Page

Aucun commentaire:

Enregistrer un commentaire