且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用URLloader将字节数组中的FLV格式数据发送到PHP脚本?

更新时间:2022-10-22 12:41:13


$ b

我现在可以成功地发送flv byteArray在php脚本中,然后php接收它并将其保存为本地系统中的flv文件并使用zend框架将其上传到***服务器中。



这是我在闪存中的代码。

  //发送byteArray到一个php脚本
var header:URLRequestHeader = new URLRequestHeader(Content-type, 应用程序/八位字节流);
var request:URLRequest = new URLRequest(url);

request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;

request.data = fs; // FLV byteArray
var loader:URLLoader = new URLLoader();
trace(request.data);
loader.load(请求)

以及接收并保存为flv的scipt file:

  $ im = $ GLOBALS [HTTP_RAW_POST_DATA]; 
$ fp = fopen(testVid.flv,'w');
fwrite($ fp,$ im);
fclose($ fp);

事实证明,我真的不需要像JPEGEncoder所做的那样对byteArray进行编码。即使如此,我仍然非常新的Flash和PHP。而且我不知道这是否是我能做的***的做法。一个建议将不胜感激。谢谢你们。


Im creating flash game that have the functionality to capture/record its gameplay that can be viewed later by the user, like a replay.

As for now Im already able to record the game and write it into a flv format in a ByteArray variable.

What Im working right now is how to send that ByteArray(the video file) to a php script and save it to a web server.

I've run into the URLLoader in flash where it can send the data and php will receive it thru the POST method. Unfortunately, the ByteArray containing the flv data must be first correclty encoded for php to read it. I figured this out from the example in the net where it does the same thing only that it is only sending a JPEG ByteArray instead of a FLV format using the JPEGENCODER.

Is there any existing class like the JpegEncoder for FLV format or any Video formats? Or any work around like creating the encoder my self?

Thanks in advance guys.

here is my current code to send the ByteArray

            //send byteArray to a php script
        var request:URLRequest = new URLRequest(url);
        request.method = URLRequestMethod.POST;

        //need to correctly encode first the ByteArray in FLV format
        //....

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);

Just figured this out.

I can now successfully send the flv byteArray in a php script where then the php receives it and save it as flv file in local system and uploading it in the *** server using zend framework.

here's my code in flash.

            //send byteArray to a php script
        var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
        var request:URLRequest = new URLRequest(url);

        request.requestHeaders.push (header);
        request.method = URLRequestMethod.POST;

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);
        loader.load(request)

and the scipt that receives and save it as a flv file:

        $im =  $GLOBALS["HTTP_RAW_POST_DATA"];
    $fp = fopen("testVid.flv", 'w');    
    fwrite($fp, $im);
    fclose($fp);

It turns out that I really dont need to encode the byteArray like what the JPEGEncoder is doing. Im still very new in flash and php though. And I have no idea if this is the best practice I can have. An advice would be greatly appreciated. Thanks guys.