0

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

<?php
$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.";
    exit();
} else if($fileSize > 5242880) {  
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); 
    exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
     echo "ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc);
     exit();
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
    echo "ERROR: An error occured while processing the file. Try again.";
    exit();
}
$moveResult = move_uploaded_file($fileTmpLoc, "final/$fileName");

if ($moveResult != true) {
    echo "ERROR: File not uploaded. Try again.";
    exit();
        }
?> 
2
Contributors
2
Replies
16
Views
1 Year
Discussion Span
Last Post by Joe_10
0

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{
exit()
}
else {
display filename 
}
0

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

Edited by Joe_10

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.