Jump to content

How do I make this form input into a variable?


Chappers

Recommended Posts

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.

[code]<?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>";
}
  }
?>[/code]

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

Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.