I'm trying to save a snapshot of a component in my flex app that is then sent to a php script to be saved and then spit back out into the browser window. I can't seem to get this to work.
Here's my FlashBuilder code:
private function saveImage():void {
var parameters:String = "snapshot=" + takeSnapshot(this);
var variables:URLVariables = new URLVariables(parameters);
var submit:URLRequest = new URLRequest("SaveImage.php");
submit.data = variables;
submit.method = URLRequestMethod.POST;
navigateToURL(submit,"_self");
}
private function takeSnapshot(component:IBitmapDrawable):String {
return ImageSnapshot.encodeImageAsBase64(ImageSnapshot.captureImage(component));
}
Here's my experimental PHP code:
$binaryData = base64_decode($_POST["snapshot"]);
$file = "mydirectory/tmp.png";
file_put_contents($file, $binaryData);
header("Content-type: image/png");
die($binaryData);
That generates the following output (where {path to image} is the url where the image was saved):
The image “{path to image}” cannot be displayed, because it contains errors.
It does save a .png file to that directory but it's blank, there's nothing there but it's dimensions are correct. I've confirmed that the snapshot works by loading it in the app with a swfLoader component right after the snapshot is taken so I know the image is good before it's sent to the server.