spacebeers
spacebeers

Reputation: 43

POST vars from flash to php file_put_contents filename

I'm recording webcam data and sending to a .php to be stored and viewed later within the flash. That element is working fine but I need to give the file a unique ID each time it does this based on variables set in flash.

here is the code I'm using to POST the flv as a 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;
     urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
     try {
             urlLoader.load( url_ref );
         } catch (e:Error) {
             trace(e);
         }

The variables I need to append to the filename set in PHP file:

    var currentVideo:String;
    var currentName:String;

My PHP file so far:

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

    $sCurrentVideo = $_POST['currentVIdeo'];

    $sCurrentName = $_POST['currentName'];
    ?>++

Can anyone here lead me in the right direction? Thanks in advance.

Upvotes: 3

Views: 639

Answers (1)

Dominic Tancredi
Dominic Tancredi

Reputation: 42332

You will want to use the "URLVariables" class.

Here is a helpful tutorial explaining it's usage.

Create an instance of it, set the values to match the two variables you want set, also add in the raw video data.

// Define the variables to post    
var urlVars:URLVariables = new URLVariables(); 
urlVars.currentVideo = currentVideo;
urlVars.currentName = currentName;
urlVars.videoData = _baFlvEncoder.byteArray;

Then in the urlReq, set the data equal to the urlVars instance:

url_ref.data = urlVars;

You will then be able to access these values in the $_POST variable in PHP.

file_put_contents("test.flv",$_POST[ 'videoData' ]);

Upvotes: 2

Related Questions