I know this has been covered, but I’ve been working at this sort of thing for months and haven’t made any significant progress. It’s time I asked you folks.
I want to upload a local text file to a server (via FileReference and some PHP) and then have Flash load it (via URLLoader). I have never gotten this to work. And I think the problem lies somewhere between the FileReference.upload() call and the dispatch of the DataEvent “uploadCompleteData”.
To simplify things, I decided this time around to make an Uploader class that handles the entire uploading process. You can view it here:
http://homepage.mac.com/rezmason/Uploader.as
There’s a chance that this class is entirely sound, and that the issue is with my PHP (which I can make no sense of anyway). But I’m trying to cover all the bases.
Once I get this to work, I’ll probably refine it to be more multipurpose. Feel free to use the class in any way you want. Heck, put it in your own package or something, it’s not like it’s a programming masterpiece. 
[FONT=Times New Roman]You can find a running example and source file here[/FONT]
[FONT=Times New Roman]package {[/FONT]
[FONT=Times New Roman]import flash.display.Sprite;[/FONT]
[FONT=Times New Roman]import flash.text.TextField;[/FONT]
[FONT=Times New Roman]import flash.events.;[/FONT]
[FONT=Times New Roman]import flash.net.;[/FONT]
[FONT=Times New Roman]import fl.controls.Button;[/FONT]
[FONT=Times New Roman]public class FileUpload extends Sprite {[/FONT]
[FONT=Times New Roman]private var _output:TextField;[/FONT]
[FONT=Times New Roman]private var _fileReference:FileReference;[/FONT]
[FONT=Times New Roman]var browseButton:Button = new Button();[/FONT]
[FONT=Times New Roman]var uploadButton:Button = new Button();[/FONT]
[FONT=Times New Roman]public function FileUpload() {[/FONT]
[FONT=Times New Roman]browseButton.move(10, 30);[/FONT]
[FONT=Times New Roman]browseButton.buttonMode = true;[/FONT]
[FONT=Times New Roman]browseButton.label = “Browse”;[/FONT]
[FONT=Times New Roman]browseButton.addEventListener(MouseEvent.CLICK, browseHandler);[/FONT]
[FONT=Times New Roman]addChild(browseButton);[/FONT]
[FONT=Times New Roman]uploadButton.move(120,30);[/FONT]
[FONT=Times New Roman]uploadButton.buttonMode=true;[/FONT]
[FONT=Times New Roman]uploadButton.label =“Upload”;[/FONT]
[FONT=Times New Roman]uploadButton.addEventListener(MouseEvent.CLICK, uploadHandler);[/FONT]
[FONT=Times New Roman]uploadButton.visible = false;[/FONT]
[FONT=Times New Roman]addChild(uploadButton);[/FONT]
[FONT=Times New Roman]_output = new TextField();[/FONT]
[FONT=Times New Roman]_output.width = 400;[/FONT]
[FONT=Times New Roman]_output.height = 400;[/FONT]
[FONT=Times New Roman]_output.y = 75;[/FONT]
[FONT=Times New Roman]addChild(_output);[/FONT]
[FONT=Times New Roman]_fileReference = new FileReference();[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(Event.SELECT, selectHandler);[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(Event.CANCEL, cancelHandler);[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(ProgressEvent.PROGRESS,progressHandler);[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityHandler);[/FONT]
[FONT=Times New Roman]_fileReference.addEventListener(Event.COMPLETE, completeHandler);[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function browseHandler(event:MouseEvent):void {[/FONT]
[FONT=Times New Roman]_fileReference.browse();[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function selectHandler(event:Event):void {[/FONT]
[FONT=Times New Roman]_output.text = “Selected File”;[/FONT]
[FONT=Times New Roman]_output.appendText("
Name: " + _fileReference.name);[/FONT]
[FONT=Times New Roman]_output.appendText("
Size: " + _fileReference.size);[/FONT]
[FONT=Times New Roman]_output.appendText("
Created On: " + _fileReference.creationDate);[/FONT]
[FONT=Times New Roman]_output.appendText("
Modified On: " +_fileReference.modificationDate);[/FONT]
[FONT=Times New Roman]uploadButton.visible = true;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function cancelHandler(event:Event):void {[/FONT]
[FONT=Times New Roman]_output.text = “Canceled”;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function uploadHandler(event:MouseEvent):void {[/FONT]
[FONT=Times New Roman]_fileReference.upload(new URLRequest(“simpleFileUpload.php”));[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function progressHandler(event:ProgressEvent):void {[/FONT]
[FONT=Times New Roman]_output.text = "file uploading
oprogress (bytes): " + event.bytesLoaded + " / " + event.bytesTotal;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function ioErrorHandler(event:IOErrorEvent):void {[/FONT]
[FONT=Times New Roman]_output.text = “an IO error occurred”;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function securityHandler(event:SecurityErrorEvent):void {[/FONT]
[FONT=Times New Roman]_output.text = “a security error occurred”;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]private function completeHandler(event:Event):void {[/FONT]
[FONT=Times New Roman]_output.text = “the file has uploaded”;[/FONT]
[FONT=Times New Roman]uploadButton.visible = false;[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman]---------------------------------------------[/FONT]
[FONT=Times New Roman]<?php[/FONT]
[FONT=Times New Roman]move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], ‘uploads/’.$_FILES[‘Filedata’][‘name’]);[/FONT]
[FONT=Times New Roman]?>[/FONT]
[FONT=Times New Roman][FONT=Times New Roman][COLOR=#800080]You can find a running example and source file here[/COLOR][/FONT][/FONT]
[FONT=Times New Roman]Regards[/FONT]
[FONT=Times New Roman]Anil[/FONT]
[FONT=Times New Roman]anilkumarnd@gmail.com[/FONT]