You can use the URLrequest and URLVariables i believe. Here is an example:
var serverURL:String = serverURL;
//Create new instance of URLrequest
var request:URLRequest = new URLRequest(serverURL);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.overwrite = "true";
variables.overwrite = "false";
variables.fileType = "jpeg";
variables.imageByteArray = encodedByteArray;
request.data = variables;
//use loader on URLrequest
var loader:URLLoader = new URLLoader();
Hi, Thanks for the reply.
But how to assign the file to 'variables'? I mean what should I assign? A file reference? or the path? I'm pasting my PHP code here to help you understand it better. I'm pretty confused. Hope you can help me.
$username = $_POST["userName"];
$password = $_POST["Password"];
$image = $_POST["image"];
$filename = $_FILES["image"]['name'];
$tmpfilename = $_FILES["image"]['tmp_name'];
$fileparts = explode(".", $filename);
$ext = $fileparts[count($fileparts) - 1];
$newfilename = substr($tmpfilename, 0, strlen($tmpfilename) - strlen($ext)) . $ext;
// The twitter API address
$url = 'http://twitter.com/account/update_profile_background_image.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array("image" => "@$newfilename"));
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
You should use HTTPService.
in the php page:
$localValue = $_REQUEST["valuePassed"];
//$localValue will contain string literal somevalue.
Have you considered using RemoteObject to access PHP functions from your Flex application? Flash Builder 4 Beta 2 has data centric wizards which help you connect your PHP code to your Flex application.
This link has some tutorials and videos which can help you get started with PHP & Flex.
Computer Scientist, Flash Builder
My question is what will be the 'somevalue' when I want to send a file? What should I use?
Gotcha. Ok, to upload a file to a php script I use the FileReference class.
public var fileref:FileReference = new FileReference();
in the function that's called when you allow them to upload
var rptTypes:FileFilter = new FileFilter("ZIP Files", "*.zip");
var allowed:Array = new Array(rptTypes);
You have to declare a urlRequest to point at your php file.
On the php side:
There's a little more to it, but there are some good examples in the
help files and the php method of dealing with uploads is well
Hope this helps.
I got it working with something similar to what you said. Thanks very much!!
But it's not working when I run it on standalone swf. Do you know any workaround?