Passing arrays from Flash to PHP

I have a problem with passing an array variable from Flash (AS2) to PHP. In a script action, I have several arrays defined this way

output["px1"] output["px2"] output["px3"] 

and then I use the following code to pass variables to a php file

 output.sendAndLoad("orders/print2cart.php",output,"POST"); 

I want to know how to get data from an array in PHP. I tried using $_POST['px1'] , $_POST['output']['px1'] , $_POST['output'] , but I can not get any data. Any ideas on what I can change to get the desired result?

Thanks!

EDIT: I noticed that one of the other variables in output (output.username) is also not sent to PHP, despite the fact that it appears in flash. Using the following code for a flash warning, and it correctly displays all the variables. getURL ("javascript: alert ('Print Stamp:" + output.PrintStamp + "User:" + output.username "')");

EDIT: It seems that when I send a fairly long array (or string, for that matter), none of the other fields associated with the LoadVars variable are sent. I searched for it for limitations, and it says that the limits of the text are ~ 63000. Still not sure if this is a problem.

+4
source share
3 answers

Since there were no other alternatives, I went through a lot of things before finally concluding that large arrays cannot be easily transferred from AS2 to PHP. My array was actually an image converted to pixels, so I did that I split the array into 2 parts and sent it to the PHP file twice, not just once. Another alternative would be to first split and send the array to a text file, and then read this text file directly from PHP.

+1
source

Try this as a string.

Use Array.join(); in flash and send the value returned by this, then use explode() in PHP to convert it to an array.

 var dataOut:LoadVars = new LoadVars(); var dataIn:LoadVars = new LoadVars(); dataOut.info = your_array.join("#"); vars.sendAndLoad("url", dataIn, "post"); dataIn.onLoad = function(go:Boolean):Void { if(go) { trace('success'); } else trace('connection failed'); } 

PHP:

 <?php $str = $_POST["info"]; $myarray = explode($str); ?> 
+3
source

You can do the same as with HTML by naming your parameters "array [0]", "array [1]", etc ....:

  var urlVariable:URLVariables = new URLVariables(); urlVariable["phpArray[0]"] = "arrayEntry0"; urlVariable["phpArray[1]"] = "arrayEntry1"; var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest("http://yourserver.com/phpScript.php"); request.method = URLRequestMethod.POST; request.data = urlVariable; loader.load(request); 

Then the servers you can check the result obtained by php script:

  print_r($_POST); 

he should output:

  Array ( [phpArray] => Array ( [0] => arrayEntry0 [1] => arrayEntry1 ) ) 

and for an array with multiple dimensions that you can use:

  urlVariable["phpArray[0][0]"] 
+1
source

All Articles