Skip to main content
GogetaX
Inspiring
April 8, 2018
Question

bitmapData.encode question

  • April 8, 2018
  • 1 reply
  • 398 views

Hey everyone, i recently posted a forum question about how to use the encoding to JPEG the best way, and i got my answer.

but im heaving trouble converting it to ByteArray.

i've tried both ways:

var b:ByteArray = new ByteArray();

b = img.encode(img.rect,new flash.display.JPEGEncoderOptions(80));

and..

var b:ByteArray = new ByteArray();

img.encode(img.rect,new flash.display.JPEGEncoderOptions(80),b);

but non of them worked. cuz i cant send it via php and save it. as this:

var php_vars: URLVariables = new URLVariables();

var php_send: URLRequest = new URLRequest("http://streamsniffer.com/sharf/upload.php");

php_send.method = URLRequestMethod.POST;

var php_loader:URLLoader = new URLLoader;

php_loader.dataFormat = URLLoaderDataFormat.VARIABLES;

php_loader.addEventListener(Event.COMPLETE,returnfunc);

var b:ByteArray = new ByteArray();

b = img.encode(img.rect,new flash.display.JPEGEncoderOptions(80));

//addChild(new img);

php_vars.img = b;

php_send.data = php_vars;

php_loader.load(php_send);

and inside my upload.php code:

<?php

if (!file_exists('uploads')) {

    mkdir('uploads', 0777, true);

}

chdir("uploads");

$a = 1;

while (file_exists($a.".jpg"))

{

    $a++;

}

$a = $a.".jpg";

if (isset( $_POST["img"]))

{

    $jpg = $_POST["img"];

    $fp = fopen( $a, 'w+' );

    fwrite($fp,$jpg);

    fclose($fp);

}

print "fname=".$a;

?>

from this whole code, my new image file is created successfully, but its empty.

any ideas where am i wrong here?

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
April 8, 2018

I don't know PHP, but apparently you can directly use byteArray as the post data. I think that would be:

php_send.data = b;

and:

$fp = fopen( $fname, "wb" );

fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );

fclose( $fp );

See this page for people who know what they're talking about!:

actionscript 3 - Flash -> ByteArray -> AMFPHP -> Invalid Image? - Stack Overflow