Return to Snippet

Revision: 5875
at April 10, 2008 10:43 by mswallace

Initial Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" creationComplete="init();">
			private var urlRequest:URLRequest;
			private var fileReferenceList:FileReferenceList;
			private var serverSideScript:String = "http://localhost/uploadFile.php";
			private function init():void {
				urlRequest = new URLRequest(serverSideScript);
				fileReferenceList = new FileReferenceList();
				fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);
			private function uploadFile():void {
			private function fileSelectedHandler(event:Event):void {
				var fileReference:FileReference;
				var fileReferenceList:FileReferenceList = FileReferenceList(;
				var fileList:Array = fileReferenceList.fileList;

				// get the first file that the user chose
				fileReference = FileReference(fileList[0]);
				// upload the file to the server side script
				fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
				// update the status text
				statusText.text = "Uploading...";
			private function uploadCompleteHandler(event:Event):void {
				statusText.text = "File Uploaded: " +;
	<mx:Label text="Upload File From Flex to PHP" fontWeight="bold"/>
	<mx:Label text="Choose a file..." id="statusText"/>
	<mx:Button click="uploadFile();" label="Upload File"/>

Initial URL

Initial Description
found this on the adobe cookbook site. There is also some PHP to go along with this in my snippets.

Initial Title
Browse for file and upload

Initial Tags
files, Flex

Initial Language