views:

32

answers:

1

I have this:

import JPGEncoder;
var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
var bm:Bitmap = new Bitmap(bmd);
bm.alpha = .5;

stage.addEventListener(MouseEvent.MOUSE_DOWN, screenCap);

function screenCap(e:Event):void {
bmd.draw(this);
var jpgVersion:JPGEncoder = new JPGEncoder( 80 );
var jpgStream:ByteArray  = jpgVersion.encode( bmd );
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://localhost/takeshot.php");
request.method = URLRequestMethod.POST;
request.data = jpgStream;
loader.load(request);
function dataOnLoad(e:Event){
 trace("Complete..");
}
}

Which takes a screenshot of the stage and is supposed to send the Byte array of the screenshot to PHP through POST data, My PHP just opens a new file, writes post data and closes (for testing purpose). But the $_POST is empty!

+1  A: 

$_POST is an array with field -> value pairs. What you send is raw post data. You can retrieve it with file_get_contents('php://input') or from $HTTP_RAW_POST_DATA, but the former is the recommended method.

Alin Purcaru
Hey, Thanks! But now the PHP file creates a JPG file but the JPG is plain black for some reason, what Flash is sending though is a screen with a gray rectangle!
Melina
Try to compute a checksum on each side to see if you get in PHP exactly what you send.
Alin Purcaru
Try to check the headers http://php.net/manual/en/function.getallheaders.php . Maybe the request is compressed.
Alin Purcaru
The headers i am recieving: x-flash-version: 10,0,22,91Content-Type: application/octet-streamContent-Length: 6650User-Agent: Shockwave FlashHost: localhostCache-Control: no-cache
Melina
Are you sure that the problem is not in the AS? You should start with checking that the encoded jpeg is good before it's sent.
Alin Purcaru
hmm i think it is the AS.. but any idea what i am ment to be checking for?
Melina
I think i will actually rewrite the code
Melina
Try setting it as a source for an image. See if that renders OK.
Alin Purcaru
Actually, i just checked the AS3 code and found it was the "true" parameter in BitmapData Method which should have been false! Thanks!
Melina