I need to save a screenshot from Flash onto my local drive. Due to some constraints, I am unfortunately unable to use FileReference as it produces a dialogue box(any way to directly save locally?) or FileStream(AdobeAir) as I am restricted to only SWF.
So I have decided to try and use PHP to get the job done.
AS3
private function takePhoto():void {
var bitmapData:BitmapData = new BitmapData(800, 650);
var encoder:JPGEncoder = new JPGEncoder(100);
var byteArray:ByteArray;
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
bitmapData.draw(camHolder);
byteArray = encoder.encode(bitmapData);
var myRequest:URLRequest = new URLRequest("save.php");
myRequest.requestHeaders.push(header);
myRequest.method = URLRequestMethod.POST;
myRequest.data = byteArray;
loader.addEventListener(Event.COMPLETE, imgSaved);
loader.load(myRequest);
}
private function imgSaved(event:Event):void {
trace(loader.data);
}
PHP
<?php
if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
$filename = "test.jpg";
file_put_contents($filename, $jpg);
}
?>
The strange thing about the trace from my AS3 imgSaved function is that it returns exactly word for word of my PHP code. No images were saved during this process as well. Any help would be appreciated!