0

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?

ieplugin
  • 661
  • 1
  • 7
  • 12
  • Forgot to mention,I'm using `JPGEncoder` in `as3corelib` with the help of this answer: http://stackoverflow.com/questions/3167636/which-package-do-i-need-to-import-to-use-jpgencoder-in-flash – ieplugin Jul 03 '10 at 00:41

1 Answers1

-1

did you try $HTTP_RAW_POST_DATA?

back2dos
  • 15,588
  • 34
  • 50
  • Wow, it works! @back2dos, can you explain why `$_POST` and `$_FILES` don't work here? – ieplugin Jul 03 '10 at 13:45
  • @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 Jul 03 '10 at 18:03
  • That was [deprecated in PHP 5.6](https://www.php.net/manual/en/migration56.deprecated.php) – Ian Dunn May 07 '22 at 15:23