Jump to content


This topic is now archived and is closed to further replies.


How do I make this form input into a variable?

Recommended Posts


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.

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">
} 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."\">


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

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...


Share this post

Link to post
Share on other sites
That field would be returned to your script in $_POST['name']


Share this post

Link to post
Share on other sites
for filename, try:
$filename = $_POST['name'] . $_FILES['file']['name'];

Not tried, just guessing :)

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.