views:

44

answers:

1

Here is the code I used to post the bitmapdata to server side(PHP):

private function savePicToServer(bmpData:BitmapData):void
{
    trace("in savePicToServer");
    trace(bmpData);
    var jpgEncoder:JPGEncoder = new JPGEncoder(85);
    var jpgStream:ByteArray = jpgEncoder.encode(bmpData);

    var loader:URLLoader = new URLLoader();

    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
    var request:URLRequest = new URLRequest("http://localhost/test.php");
    request.requestHeaders.push(header);
    request.method = URLRequestMethod.POST;
    request.data = jpgStream;
    loader.load(request);
    trace("finish savePicToServer");
}

Here is the code at server side:

file_put_contents('data.txt',var_export($_POST) . var_export($_FILES) . "\r\n" . $_SERVER['REMOTE_ADDR']);

But in data.txt only this:

127.0.0.1

Finally the trace output is :

in savePicToServer
[object BitmapData]
finish savePicToServer

What's wrong with my code above?

A: 

did you try $HTTP_RAW_POST_DATA?

back2dos
Wow, it works! @back2dos, can you explain why `$_POST` and `$_FILES` don't work here?
ieplugin
@ieplugin: `$_POST` is an array containing all parameters sent per post and `$_FILES` is an array of all files uploaded as such. You would get this using `flash.net.FileReference::upload`. However, in this case, the content is uploaded as plain post content.
back2dos