views:

62

answers:

2

I am trying to save some images from Flash to Php by sending a jpgstream, capturing it in php and pushing it to a file. Not sure what I am doing wrong here.

I am putting all the images I need into an array like so: (history is just where I am keeping all the image data)

for each($value in history)
            {

                var jpgSource:BitmapData = new BitmapData ($value.sourceImg.width, $value.sourceImg.height);
                jpgSource.draw($value.sourceImg);
                var encoder:JPEGEncoder = new JPEGEncoder(100);
                var jpgStream:ByteArray =  encoder.encode(jpgSource);
                var imgDetailArr:Array = new Array(jpgStream, $value.name);
                imgArr.push(imgDetailArr);



            }

And then i send that to PHP using a remote object and amfphp:

rmObj.saveUserImages( imgArr);

On the php side I am doing this:

function saveUserImages( $imgArr)
    {
        foreach($imgArr as $value)
        {


            ob_start();
            /* output image as JPEG */
            $image = imagecreatefromjpeg($value[0]);     
            header('Content-type: image/jpeg');
            imagejpeg( $image );
            /* save output as file */
            ob_flush();
            file_put_contents( "images", ob_get_contents() );


        }
    }

But this doesn't seem to do the trick. I have been going through a bunch of different tutes and code snippets, so maybe I just ogt something confused along the way. I have done this before though and don't remember it being this difficult.

A: 

You may be better off calling JS from Flash and pass a path to the file via AJAX. Then, use PHP to upload the files directly. PHP has support for file uploads from a hard drive.

Edit:

On second thought, try switching ob_flush with the line after it. It looks like you are deleting your temporary data before saving it.

Moshe
But these are images created in flash, I'm trying to push these images to a folder. Not sure what path I would use for the ajax if they aren't yet in a directory.
pfunc
You are right. See my edit.
Moshe
oh sheesh... you are right. Thanks!
pfunc
A: 

im no expert on flash but this seems to be doing what you are looking for ... thoughts?

http://henryjones.us/articles/using-the-as3-jpeg-encoder

sfmoe
I am actually using the jpegencoder.. but I want to incorporate it with the flex remote object and amfphp, not as3 loaders. Having a little bit of a tough time doing that.
pfunc