Uploading file to Server is killing me!

Hi all, this problem is really killing me.

I have AS3 browsing using the .browse()
it then sends to my PHP script and that should be fine!
The AS3 tells me that it is working.
The PHP tells me that it is receiving the file.
So there should be no problem… But it seems to think that the file I am trying to upload already exists and then it fails to save the file to the server. When I use HTML instead of .swf it works fine.

My PHP works fine when I interact with it using HTML.

So my AS3 looks like this:
[AS]package
{
import flash.display.Sprite;
import flash.events.*;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.URLRequest;

public class FileUpload extends Sprite
{
var fileRef:FileReference = new FileReference();

public function FileUpload() 
{
	fileRef.addEventListener(Event.SELECT, selectHandler); 
	fileRef.addEventListener(Event.COMPLETE, completeHandler); 
	try 
	{ 
		var success:Boolean = fileRef.browse(); 
	} 
	catch (error:Error) 
	{ 
		trace("Unable to browse for files."); 
	} 
}    
function selectHandler(event:Event):void 
{ 
	var request:URLRequest = new URLRequest("http://www.*****.com/test/FileUpload.php") 
	try 
	{ 
		fileRef.upload(request); 
	} 
	catch (error:Error) 
	{ 
		trace("Unable to upload file."); 
	} 
}

function completeHandler(event:Event):void 
{ 
	trace("uploaded"); 
}

}
}[/AS]

My PHP looks like this:

<?php
	$myFile = "log.txt"; // used for logging progress
	$fh = fopen($myFile, 'a') or die("can't open file");// used for logging progress
	
	if ($_FILES["file"]["error"] > 0)
	{
		echo "Error: " . $_FILES["file"]["error"] . "<br />";
		$stringData = "PHP Error
";// used for logging progress
		fwrite($fh, $stringData);  // used for logging progress
	}

	if (file_exists("upload/" . $_FILES["file"]["name"]))
	{
		echo $_FILES["file"]["name"] . " already exists. ";
		$stringData = "PHP file alreadyExists
";// used for logging progress
		fwrite($fh, $stringData);// used for logging progress
	}
	else
	{
		move_uploaded_file($_FILES["file"]["tmp_name"],  "upload/" . $_FILES["file"]["name"]);
		echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
		$stringData = "File move
";// used for logging progress
		fwrite($fh, $stringData);// used for logging progress
	}
	
	fclose($fh);
?>

When I use the .swf it writes “PHP file alreadyExists” into the log.txt and there is no files in the upload directory what so ever (and the browser cache is clear)

When I use the .htm it writes “File move” into the log.txt and copies the file.

I am trying to follow the examples from

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf8.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7ce9

Thank you for taking the time to look at this, I have spent days on what I thought would be a fairly simple issue!