Browse button that captures text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sheridan
Forum Newbie
Posts: 18
Joined: Sat May 31, 2008 1:50 pm

Browse button that captures text

Post 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?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Browse button that captures text

Post by aceconcepts »

When you submit the form you can ge the file name like this:

Code: Select all

$file_name_only = $_FILES['userfile']['name'];
Sheridan
Forum Newbie
Posts: 18
Joined: Sat May 31, 2008 1:50 pm

Re: Browse button that captures text

Post by Sheridan »

GREAT!!! Where is this code inserted?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Browse button that captures text

Post 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'];
}
 
Sheridan
Forum Newbie
Posts: 18
Joined: Sat May 31, 2008 1:50 pm

Re: Browse button that captures text

Post by Sheridan »

Works like a dream!! Much thanks!
Post Reply