如何将 ByteArray(来自 Flash)和一些表单数据发送到 php? [英] How can I send a ByteArray (from Flash) and some form data to php?

查看:32
本文介绍了如何将 ByteArray(来自 Flash)和一些表单数据发送到 php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Flash AS3 制作的画板,就像这里的一个:http://henryjones.us/articles/using-the-as3-jpeg-encoder

I have a sketch pad made in Flash AS3 like this one here: http://henryjones.us/articles/using-the-as3-jpeg-encoder

我想用 php 将 jpg 发送到服务器和一些来自 html 表单字段的数据.有没有办法在按下提交按钮时强制 Flash 电影传送图像文件?

I want to send the jpg to the server and some data from a html form field with php. Is there a way to force the Flash movie to deliver the image file when one presses the submit button?

推荐答案

这有点棘手:您可以通过以下两种方式之一进行:

it's a little tricky: You can do it one of two ways:

Arthem 在另一个帖子中发布了这个:

Arthem posted this in another thread:

这对我帮助很大:http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/

您需要修改URLRequestWrapper 插入字段需要的名称和文件名.这是我所做的:

You need to modify the URLRequestWrapper to insert field names and file names where needed. Here's what I've done:

bytes = '内容配置:表单数据;名称="' + $fieldName + '";文件名="';

bytes = 'Content-Disposition: form-data; name="' + $fieldName + '"; filename="';

它对标题进行了最多的格式化因此服务器可以将其理解为文件上传.

It does the most formatting of headers so the server could understand it as a file upload.

顺便说一下,如果你有一个 BitmapData您可能需要将其编码为 JPEG 或首先是 PNG.

By the way, if you have a BitmapData you might need to encode it to JPEG or PNG first.

我通常使用这个解决方案:

And I usually use this solution:

我没有使用过 imageshack API,但您可能想尝试使用 adobe 的 JPGEncoder 类 - 这是一个传递用户名和 JPG 字节数组的快速示例,它真的很简单.

I haven't used the imageshack API, but you may want to try using adobe's JPGEncoder class - here's a quick example that passes a username and the JPG's byte array, it's really quite simple.

private function savePicToServer(bmpData:BitmapData):void
{
    var jpgEncoder:JPGEncoder = new JPGEncoder(85);
    var jpgStream:ByteArray = jpgEncoder.encode(bmpData);

    var loader:URLLoader = new URLLoader();
        configureListeners(loader);

    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
    var request:URLRequest = new URLRequest(ModelLocator.BASE_URL + ModelLocator.UPLOAD_URL + "?user=" + ModelLocator.getInstance().username);
    request.requestHeaders.push(header);
    request.method = URLRequestMethod.POST;
    request.data = jpgStream;
    loader.load(request);
}

请注意,变量是作为查询字符串的一部分传递的.您不能使用 URLVariables,正如一些人所建议的那样,因为 URLVariables 将存储在请求的 data 属性中,我们已经使用它来传递 byteArray.

Note that the variables are passed as part of the query string. You can't use URLVariables, as several people have suggested, as the URLVariables would be stored in the request's data property, which we are already using to pass the byteArray.

这篇关于如何将 ByteArray(来自 Flash)和一些表单数据发送到 php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆