Maybe you don't have a version of amfphp that supports AS 3.0 objects...

Check this out:

http://www.sephiroth.it/tutorials/flashPHP/amfphp_bytearray/

On the other hand, if using amfphp is not a requirement, you could just use
the class I posted, and handle things from the php side as if it were a
regular html form post.

Cheers
Juan Pablo Califano

2008/8/16, Omar Fouad <[EMAIL PROTECTED]>:
>
> When I use ba without toString() amfphp says "Object of class ByteArray
> could not be converted to string".
> I think there is something to be done in the php to convert the data back
> from string into binary data, but I cannot find it out.
>
> Ideas?
>
> On Sat, Aug 16, 2008 at 9:02 PM, Juan Pablo Califano <
> [EMAIL PROTECTED]> wrote:
>
> > I haven't used amfphp extensively, but it might be a problem in the type
> > of data amfphp expects... I'm not sure this is a good idea:
> >
> > ba.toString()
> >
> > As with a JPG you'll sure get lots of 0's in the ByteArray; parsed as a
> > char
> > in a string, a 0 value is what's known as an embedded null, which
> > traditionally is used to signal the end of the string, so probably at
> some
> > point the data is being truncated.
> >
> > Maybe if you just send the ByteArray object, amfphp will figure out the
> > type
> > of the object and will be able to deserialize it correctly. I think
> that's
> > the whole idea behind amfphp, it automatically serializes and
> deserializes
> > native objects using the amf format.
> >
> >
> > Cheers
> > Juan Pablo Califano
> >
> >
> > 2008/8/16, Omar Fouad <[EMAIL PROTECTED]>:
> > >
> > > well I've been trying this amfphp and it does not work. amfphp responds
> > > back
> > > an error saying "amfphp_runtime_error".
> > >
> > > I have this php file in the services dir which hace this function  that
> I
> > > call throuh actionscript
> > >
> > > function getData($image)
> > > {
> > >        $data = mysql_query("Insert into table01 (image) values
> > > ('$image')");
> > >        if($data == null) {
> > >           return false;
> > >        }eles{
> > >           return true;
> > >       }
> > > }
> > >
> > > in the mysql database there is a longblob field image and in fd I
> wrote:
> > >
> > > [Embed(source = 'mail[1].jpg')]
> > >        private var _img:Class;
> > >        private var img:Bitmap = new _img();
> > >
> > >        private var gw:NetConnection;
> > >        private var res:Responder;
> > >        private var TF:TextField = new TextField();
> > >
> > >        private var ba:ByteArray;
> > >        private var encoder:JPGEncoder;
> > >        private var bd:BitmapData;
> > >
> > >        public function Main():void {
> > >
> > >            TF.autoSize  = TextFieldAutoSize.LEFT;
> > >            addChild(TF);
> > >
> > >            bd = new BitmapData(img.width, img.height);
> > >            bd.draw(img);
> > >            encoder = new JPGEncoder(90);
> > >            ba = encoder.encode(bd);
> > >
> > >            gw = new NetConnection();
> > >            gw.connect("http://localhost/amfphp/amfphp/gateway.php";);
> > >            res = new Responder(onResult, onFault);
> > >            gw.call("Test.getData", res, ba.toString());
> > >        }
> > >
> > >        private function onResult(responds:Object):void {
> > >            TF.text = String(responds);
> > >        }
> > >
> > >        private function onFault(responds:Object):void {
> > >            for (var i:* in responds) {
> > >                    TF.text = String(responds[i]);
> > >            }
> > >        }
> > >
> > > Is there something I missed in the AS or PHP?
> > >
> > > Thanks
> > >
> > >
> > >
> > > On Sat, Aug 16, 2008 at 2:16 AM, Omar Fouad <[EMAIL PROTECTED]>
> > > wrote:
> > >
> > > > Thanks.. I will try this now and feed you back.
> > > >
> > > >
> > > >
> > > > On Sat, Aug 16, 2008 at 1:41 AM, Juan Pablo Califano <
> > > > [EMAIL PROTECTED]> wrote:
> > > >
> > > >> Yes. Using that particular class I mentioned, from the php side
> you'd
> > > >> receive the data like a regular html form post with
> multipart-encode,
> > > that
> > > >> means, you can retrieve the text variables you want to send with
> > > >> $_POST['someVar'] and the file (or files) with $_FILES['varName']
> (or
> > > the
> > > >> name you choose). Treat it like if it were a html form.
> > > >>
> > > >> To add a text field to the form use the add
> > > addField("varName","varValue")
> > > >> method; to add a file, use addFile("varName", jpgByteArray,
> > > >> "originalFileName", imageMimeType);
> > > >>
> > > >> For "originalFileName", use whatever you want, like "image.jpg", it
> > > >> doesn't
> > > >> really matter. That's what you'll get with
> $_FILES['varName']['name'].
> > > For
> > > >> the imageMimeType, use the constant in the class for JPG.
> > > >>
> > > >>
> > > >> Cheers
> > > >> Juan Pablo Califano
> > > >>
> > > >> 2008/8/15, Omar Fouad <[EMAIL PROTECTED]>:
> > > >> >
> > > >> > I guess I can send the ByteArray to the php that will handle its
> > > >> insertion
> > > >> > to the database. Right?
> > > >> >
> > > >> > On Fri, Aug 15, 2008 at 7:07 PM, Juan Pablo Califano <
> > > >> > [EMAIL PROTECTED]> wrote:
> > > >> >
> > > >> > > With the newest player, I think, it's possible to save data into
> > the
> > > >> > USER's
> > > >> > > hard drive without a trip to the server, but you want to store
> the
> > > >> data
> > > >> > on
> > > >> > > the server side, you need to send it to the server...
> > > >> > >
> > > >> > > You have to post that data using a URLLoader object, and
> > specifying
> > > >> the
> > > >> > > input as binary data.
> > > >> > >
> > > >> > > I've wrapped up some code to do that and being able to pass
> > > variables
> > > >> as
> > > >> > > well. If you want to check it out:
> > > >> > >
> > > >> > > http://pastebin.com/f11a897cf
> > > >> > >
> > > >> > > (Sorry, comments are in Spanish, but the indentifiers are in
> > > English)
> > > >> > >
> > > >> > > A example of use (it's a copy & paste from some wortking code,
> > just
> > > to
> > > >> > give
> > > >> > > you an idea):
> > > >> > >
> > > >> > >
> > > >> > > import ar.com.califa010.utils.FormData;
> > > >> > >
> > > >> > >   // getEncodedImg() is a method that returns a JPG as a
> byteArray
> > > >> > >
> > > >> > >   var rawJpg:ByteArray = getEncodedImg();
> > > >> > >   var formData:FormData = new FormData();
> > > >> > >
> > > >> > >   var imageMimeType:String = FormData.JPG_FILE;
> > > >> > >   var fileName:String = "imageFile.jpg";
> > > >> > >
> > > >> > >   formData.addFile("imageFile", rawJpg, fileName,
> imageMimeType);
> > > >> > >
> > > >> > >
> > > >> > >   formData.addField("sFormat",imgFormat);
> > > >> > >   formData.addField("idImagen",_idImagen);
> > > >> > >
> > > >> > >   var req:URLRequest  = new URLRequest(url);
> > > >> > >
> > > >> > >   req.method   = "POST";
> > > >> > >   req.contentType  = formData.contentType;
> > > >> > >   req.data   = formData.getPostData();
> > > >> > >
> > > >> > >   var loader:URLLoader = new URLLoader();
> > > >> > >   configureListeners(loader);
> > > >> > >
> > > >> > >    loader.load(req);
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> > > 2008/8/15, Omar Fouad <[EMAIL PROTECTED]>:
> > > >> > > >
> > > >> > > > I see, all those tutorials shows how to save the image on the
> > Hard
> > > >> > Drive
> > > >> > > > (now with flash player is possible to do this without any
> server
> > > >> side
> > > >> > > > script).
> > > >> > > >
> > > >> > > > But considering my question, what I should be putting in my
> > > database
> > > >> > row,
> > > >> > > > the byteArray encoded by JPGEncoder?
> > > >> > > > Is there a method into this class that takes the ByteArray
> from
> > > the
> > > >> > > > database
> > > >> > > > back, and translates it into a bitmap to be shown in the swf?
> > > >> > > >
> > > >> > > > On Fri, Aug 15, 2008 at 12:42 PM, Glen Pike <
> > > >> [EMAIL PROTECTED]
> > > >> > > > >wrote:
> > > >> > > >
> > > >> > > > > Hi,
> > > >> > > > >
> > > >> > > > >   Sorry, I put this in the wrong thread before - here is my
> 2c
> > > >> > > > >
> > > >> > > > >   Hi,
> > > >> > > > >
> > > >> > > > >  There are a few examples on the www about sending Bitmap
> data
> > > to
> > > >> the
> > > >> > > > > server Mario's is a good starting point -
> > > >> > > > > http://www.quasimondo.com/archives/000572.php      Anyway,
> > > there
> > > >> are
> > > >> > > > other
> > > >> > > > > examples about which do compression/decompression on your
> data
> > > so
> > > >> you
> > > >> > > > could
> > > >> > > > > save it into your DB too..
> > > >> > > > >
> > > >> > > > >  Hope this is useful
> > > >> > > > >
> > > >> > > > >  Glen
> > > >> > > > > --
> > > >> > > > >
> > > >> > > > > Glen Pike
> > > >> > > > > 01326 218440
> > > >> > > > > www.glenpike.co.uk <http://www.glenpike.co.uk>
> > > >> > > > >
> > > >> > > > >
> > > >> > > > > ______________________________________________
> > > >> > > > > Flashcoders mailing list
> > > >> > > > > [email protected]
> > > >> > > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >> > > > >
> > > >> > > >
> > > >> > > >
> > > >> > > >
> > > >> > > > --
> > > >> > > > Omar M. Fouad - Digital Emotions
> > > >> > > > http://www.omarfouad.net
> > > >> > > >
> > > >> > > > This e-mail and any attachment is for authorised use by the
> > > intended
> > > >> > > > recipient(s) only. It may contain proprietary material,
> > > confidential
> > > >> > > > information and/or be subject to legal privilege. It should
> not
> > be
> > > >> > > copied,
> > > >> > > > disclosed to, retained or used by, any other party. If you are
> > not
> > > >> an
> > > >> > > > intended recipient then please promptly delete this e-mail and
> > any
> > > >> > > > attachment and all copies and inform the sender. Thank you.
> > > >> > > > _______________________________________________
> > > >> > > > Flashcoders mailing list
> > > >> > > > [email protected]
> > > >> > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >> > > >
> > > >> > > _______________________________________________
> > > >> > > Flashcoders mailing list
> > > >> > > [email protected]
> > > >> > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >> > >
> > > >> >
> > > >> >
> > > >> >
> > > >> > --
> > > >> > Omar M. Fouad - Digital Emotions
> > > >> > http://www.omarfouad.net
> > > >> >
> > > >> > This e-mail and any attachment is for authorised use by the
> intended
> > > >> > recipient(s) only. It may contain proprietary material,
> confidential
> > > >> > information and/or be subject to legal privilege. It should not be
> > > >> copied,
> > > >> > disclosed to, retained or used by, any other party. If you are not
> > an
> > > >> > intended recipient then please promptly delete this e-mail and any
> > > >> > attachment and all copies and inform the sender. Thank you.
> > > >> > _______________________________________________
> > > >> > Flashcoders mailing list
> > > >> > [email protected]
> > > >> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >> >
> > > >> _______________________________________________
> > > >> Flashcoders mailing list
> > > >> [email protected]
> > > >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > Omar M. Fouad - Digital Emotions
> > > > http://www.omarfouad.net
> > > >
> > > > This e-mail and any attachment is for authorised use by the intended
> > > > recipient(s) only. It may contain proprietary material, confidential
> > > > information and/or be subject to legal privilege. It should not be
> > > copied,
> > > > disclosed to, retained or used by, any other party. If you are not an
> > > > intended recipient then please promptly delete this e-mail and any
> > > > attachment and all copies and inform the sender. Thank you.
> > > >
> > >
> > >
> > >
> > > --
> > > Omar M. Fouad - Digital Emotions
> > > http://www.omarfouad.net
> > >
> > > This e-mail and any attachment is for authorised use by the intended
> > > recipient(s) only. It may contain proprietary material, confidential
> > > information and/or be subject to legal privilege. It should not be
> > copied,
> > > disclosed to, retained or used by, any other party. If you are not an
> > > intended recipient then please promptly delete this e-mail and any
> > > attachment and all copies and inform the sender. Thank you.
> > > _______________________________________________
> > > Flashcoders mailing list
> > > [email protected]
> > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > >
> > _______________________________________________
> > Flashcoders mailing list
> > [email protected]
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
>
>
>
> --
> Omar M. Fouad - Digital Emotions
> http://www.omarfouad.net
>
> This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an
> intended recipient then please promptly delete this e-mail and any
> attachment and all copies and inform the sender. Thank you.
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to