如何保存字节组通过PHP的服务器上? [英] How do I save bytearray on the server via php?

查看:154
本文介绍了如何保存字节组通过PHP的服务器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用简单的AS3 + PHP,FM或者这样在两者之间。我想提出一个视频录制应用程序,我可以捕获帧,并将它们转换为flv EN codeD字节组。但是,当我尝试将其保存在服务器上的问题发生。如果我的ByteArray转换为字符串通过的base64 EN code,然后发送字符串到服务器,所有工程确定,但问题是,由于它是一个视频文件,也可以是pretty的大,像20MB左右,因此它需要很长的时间来恩code,然后上传,而且通常会出现一个脚本超时在编码过程中。为了使事情更快,我想直接发送字节数组,但我的萤火虫网面板显示我正在发送的数据大约是20-46个字节。请告诉我,我做错了。

  //变种EN coded_str = Base64.en codeByteArray(_baFlvEn coder.byteArray);
            //处理上传
            / * VAR url_data:使用URLVariables =新的URLVariables();
            url_data.data = _baFlvEn coder.byteArray; * /
            VAR url_ref:的URLRequest =新的URLRequest(save_vid.php);

            url_ref.contentType ='应用程序/八位字节流;
            url_ref.data = _baFlvEn coder.byteArray; // url_data;
            url_ref.method = URLRequestMethod.POST;

            VAR的URLLoader:的URLLoader =新的URLLoader();

            //只是确保服务器知道我们是在正确的格式发送数据
            //urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

            尝试 {
                对URLLoader.load(url_ref);
            }赶上(五:错误){
                跟踪(E);
            }
 

和我的PHP code:

 < PHP
回声的数据:; pre>';
的print_r($ _ POST);
回声'< / pre>';
// $日codedData = base64_de code($ GLOBALS ['HTTP_RAW_POST_DATA']);
//file_put_contents("test.flv",$de$c$cdData);
file_put_contents(test.flv,$ GLOBALS ['HTTP_RAW_POST_DATA']);
?>
 

解决方案

在<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#data"相对=nofollow> 请将URLRequest.data 文档,它指定直接使用的ByteArray的选择。

下面,

  urlLoader.data = _baFlvEn coder.byteArray;
 

您就可以跳过的URLVariables 对象,这依赖于编码你发送的数据为应用程序/ x-WWW的形式urlen $ C $光盘,这是不适合的二进制数据(即使它被适当地处理,这可能不是)。

I am using simple as3+php, no FMS or such in between. I am making a video recording app, and I can capture frames and convert them to flv encoded bytearray. But the problem happens when I try to save it on the server. If I convert the bytearray to a string via base64 encode and then send that string to the server, all works ok, but the problem is that since it's an video file, it can be pretty big, like 20mb or so, and hence it takes a long time to encode it and then upload it, moreover normally a script timeout will occur during the encoding. To make things faster, I am trying to send the bytearray directly, but my firebug net panel shows me that the data being sent is around 20-46 bytes. Please tell me what I am doing wrong.

//var encoded_str = Base64.encodeByteArray(_baFlvEncoder.byteArray);
            //Handle Upload
            /*var url_data:URLVariables = new URLVariables();
            url_data.data = _baFlvEncoder.byteArray;*/
            var url_ref:URLRequest = new URLRequest("save_vid.php");

            url_ref.contentType = 'application/octet-stream';
            url_ref.data = _baFlvEncoder.byteArray;//url_data;
            url_ref.method = URLRequestMethod.POST;

            var urlLoader:URLLoader = new URLLoader();

            // just making sure the server knows we are sending data in proper format
            //urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

            try {
                urlLoader.load( url_ref );
            } catch (e:Error) {
                trace(e);
            }

And my PHP code:

<?php
echo 'Data:<pre>';
print_r($_POST);
echo '</pre>';
//$decodedData= base64_decode($GLOBALS[ 'HTTP_RAW_POST_DATA' ]);
//file_put_contents("test.flv",$decodedData);
file_put_contents("test.flv",$GLOBALS[ 'HTTP_RAW_POST_DATA' ]);
?>

解决方案

In the URLRequest.data documentation, it specifies the option of using a ByteArray directly.

Here,

urlLoader.data = _baFlvEncoder.byteArray;

You can then skip the URLVariables object, which relies on encoding your transmitted data as application/x-www-form-urlencoded, which is not well suited to binary data (even if it were handled properly, which it may not be).

这篇关于如何保存字节组通过PHP的服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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