Jump to content


Photo

How do I make this form input into a variable?


  • Please log in to reply
2 replies to this topic

#1 Chappers

Chappers
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 11 July 2006 - 10:00 AM

Hi

I'm using this simple upload form to upload image files to a folder on my server, and I'm trying to add another form input in the form of a text input. I wanted to have this text input added to the first part of an uploaded file's name so I know who's sent it, but I can't work out how to do it. I've tried and tried, and I've searched the net but it's not easy to search for.

<?php
if(!isset($_POST['upload'])) {
echo '
<form name="upload" enctype="multipart/form-data" method="POST" action="'.$_SERVER['REQUEST_URI'].'">
<input type="file" name="file" value=""><br>
Name: <input type="text" name="name" size="20">
<br><input type="submit" name="upload" value="Upload">
</form>
';
} else {
$yourdomain = 'http://example.net/';
$uploaddir = 'files/';
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$tmpname_file = $_FILES['file']['tmp_name'];
$date_file = date(dmY);
if($filesize > '102400') {
echo "File is too big!";
} else {
move_uploaded_file($tmpname_file, "$uploaddir$date_file$filename");
echo "File uploaded Successfully.<br />URL to your file: <a href=\"http://example.net/".$uploaddir.$date_file.$filename."\"> 

http://example.net/".$uploaddir.$date_file.$filename."</a>";
}
  }
?>

The field I've added can be seen above as :
Name: <input type="text" name="name" size="20">

Could someone please tell me how I pass this to be added to the file's name? I can work out what to do once I've made it a variable ($blahblah) but don't know how to make it one. I assumed it had to be done in the section of code where the $filename, $filesize are done...

Thanks

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 11:56 AM

That field would be returned to your script in $_POST['name']

Ken

#3 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 01:39 PM

for filename, try:
$filename = $_POST['name'] . $_FILES['file']['name'];

Not tried, just guessing :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users