简体   繁体   English

使用PHP将图像从闪存保存到服务器

[英]Saving images from flash to server using PHP

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. 我正在尝试通过发送jpgstream,将其捕获到php中并将其推送到文件中来将一些图像从Flash保存到Php。 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: 然后我使用远程对象和amfphp将其发送到PHP:

rmObj.saveUserImages( imgArr);

On the php side I am doing this: 在PHP方面,我正在这样做:

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. 我以前曾经做过这个,并且不记得它这么难。

You may be better off calling JS from Flash and pass a path to the file via AJAX. 您最好从Flash调用JS并通过AJAX传递文件路径。 Then, use PHP to upload the files directly. 然后,使用PHP直接上传文件。 PHP has support for file uploads from a hard drive. PHP支持从硬盘驱动器上传文件。

Edit: 编辑:

On second thought, try switching ob_flush with the line after it. 再次考虑,尝试用ob_flush的行切换ob_flush It looks like you are deleting your temporary data before saving it. 好像您在删除临时数据之前将其保存。

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 http://henryjones.us/articles/using-the-as3-jpeg-encoder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM