Page 1 of 1

Browse button that captures text

Posted: Sat Oct 11, 2008 2:19 pm
by Sheridan
I want to create a "browse" button that will upload the NAME of a file (just the name, NOT the file) and pass that name onto another page. I have written the following:

Code: Select all

 
echo '<FORM ENCTYPE="multipart/form-data" ACTION="InsertImageFile.php" METHOD=POST>';
 
 echo '<table cellpadding = 5 border = 1> <tr><td>';
 echo 'File Name </td><td>';
 echo '<INPUT NAME="FileName" size ="45" TYPE="file">';
 
 echo '</td></tr> <tr><td>';
 
 echo 'Description </td><td> <input type = "text" name = "PicDescrip" size ="45" value = "">';
  echo '</td></tr> <tr><td>';
 
 echo '<input type = "submit" value = "Add Image"> </td></tr></table></center></form>';
 
 
When this code executes nothing is sent to the receiving page. Am I right is guessing that the system is trying to send the file instead of the text of the file name?

How do I fix this?

Re: Browse button that captures text

Posted: Sat Oct 11, 2008 2:24 pm
by aceconcepts
When you submit the form you can ge the file name like this:

Code: Select all

$file_name_only = $_FILES['userfile']['name'];

Re: Browse button that captures text

Posted: Sat Oct 11, 2008 2:26 pm
by Sheridan
GREAT!!! Where is this code inserted?

Re: Browse button that captures text

Posted: Sat Oct 11, 2008 2:28 pm
by aceconcepts
If you want to get the text within the same file as the form, then execute it before the form e.g.

Code: Select all

 
if(isset($_POST['submit']))
{
$file_name_only = $_FILES['userfile']['name'];
}
 

Re: Browse button that captures text

Posted: Sat Oct 11, 2008 2:38 pm
by Sheridan
Works like a dream!! Much thanks!