Checking File on upload Help

i have this script which is the upload but how do i check

System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();

// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
  //clean statusArea and details area
  statusArea.text = details.text = ""
  // Flash is attempting to upload the image.
  //statusArea.text += "Attempting to upload " + selectedFile.name + "
";
  statusArea.text = "Attempting to upload " + selectedFile.name;
  filenameArea.text = selectedFile.name;
  // Upload the file to the PHP script on the server.
  selectedFile.upload("upload.php");
};

// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
  filenameArea.text = selectedFile.name;
  statusArea.text += "Uploading " + selectedFile.name + "
";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"
File: "+ file.name;
}

listener.onIOError = function(file:FileReference):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "IOError: "+ file.name;
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"
File: "+ file.name;    
}

// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
  // Notify the user that Flash is starting to download the image.
  //statusArea.text += "Upload finished.
Now downloading " + selectedFile.name + " to player
";
  filenameArea.text = selectedFile.name;
  statusArea.text = "Upload finished. ";
  //Show file details
  details.text = ""
  for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile*+"
"
  // Call the custom downloadImage() function.
  downloadImage(selectedFile.name);
};

var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);

uploadBtn.onPress = uploadImage;
imagePane.addEventListener("complete", imageDownloaded);

// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
  imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}



but where do i check for the file exists when i upload a picture ?

or if picture exists it will be automatically renamed or shows invalid file please try rename and upload again?

anyone can help me here ?