I have a simple form that I want the user to input their name and submit a picture. The name user name and photoname will goto the database. The form submits to the database, and fileuploads and renames correctly. My issue is how to I return the renamed filename to the original form. If it matters the up load form is on a popup. below is are the file select and upload scripts.

<form enctype="multipart/form-data" method="post" action="newtestupload.php">
Choose your file here:
<input name="uploaded_file" type="file"/><br /><br /> <input type="submit" value="Upload It" /> </form>

                     the upload script

$fileName = $_FILES["uploaded_file"]["name"];  
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; 
$fileType = $_FILES["uploaded_file"]["type"]; 
$fileSize = $_FILES["uploaded_file"]["size"];  
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; 
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName); 
$boom = explode(".", $fileName); 
$fileExt = end($boom); 
$fileName = time().rand().".".$fileExt;
$fileName2 = $fileName; 

if (!$fileTmpLoc) {  
    echo "ERROR: Please browse for a file before clicking the upload button.";
} else if($fileSize > 5242880) {  
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
     echo "ERROR: Your image was not .gif, .jpg, or .png.";
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
    echo "ERROR: An error occured while processing the file. Try again.";
$moveResult = move_uploaded_file($fileTmpLoc, "final/$fileName");

if ($moveResult != true) {
    echo "ERROR: File not uploaded. Try again.";

You could add a few lines after that last if statement as an else to it (ie it has successfully been moved) to display the filename in another pop-up perhaps.
putting it rather crudely,

If (moved) !=true{
else {
display filename 

it is displayting the file name on the popup window. I am trying to return the filename to the form so I can submit to a database. I want to insert the username and photoname