1

I have an ActionScript 3 application that's sending an object to PHP via ZendAMF. The object contains a byteArray from an image.

I have it currently saving the byteArray into a Blob like so:

$ba = new Zend_Amf_Value_ByteArray ( $im->bArray );
$data = mysql_real_escape_string ( $ba->getData () );

$query = "INSERT INTO  image ( byteArray ) VALUES ( '".$data."' );";
$result = mysql_query($query);
$error = mysql_error();

if($error)
 return "Error: " . $error;
else
 return true;

This seems to be working fine and I can see the image in the DB (this is running local and I'm using SequelPRO to view the DB).

The problem is when I'm sending the byteArray back to Flash, Flash reports the byteArray length as 0.

Here is my return method in PHP:

$result = mysql_query ( 'SELECT * FROM image');
$array = array();

while ( $row = mysql_fetch_assoc ( $result ) )
{
 $ba = new Zend_Amf_Value_ByteArray ( $row['byteArray'] );

 $image = new Image ();
 $image->id = $row['id'];
 $image->file = $row['filePath'];
 $image->bArray = $ba->getData();

 array_push ( $array, $image );
}

return ( $array );

Is there a better way to do this? Any help would be greatly appreciated.

Thank you

Yav
  • 106
  • 7

1 Answers1

1

Just from a quick google of Zend_Amf_Value_ByteArray , seems that there might be a problem with Zend itself in that it has a problem not properly serializing your byte array.

Here are a few links to the Zend forums that talk about this issue:

  1. Zend_Amf does not properly serialize Zend_Amf_Value_ByteArray instances
  2. ByteArray does not serialize to Zend_Amf_Value_ByteArray. Instead a string is given
  3. Flex 4 / PHP Data-Centric Photo Transfers

Good luck, and hope this helps you some.

Chris
  • 6,272
  • 9
  • 35
  • 57
  • Looks like the byte array gets to PHP and into the DB with no problem, then I can pull it out of the DB and build out an object in PHP but when Flash gets the object back it's doesn't see the byte array as a byte array. – Yav Jan 06 '11 at 21:25