Adding a username

Hi. I am making a file sharing website but don’t know how to get there to be the text after the file name (i.e. the text would say “uploaded by [username]”.

So far I have the key $_SESSION[‘Username’] but I don’t know how or where to add it to the upload script:

<?php $limit_size=2097152; $file_name = $HTTP_POST_FILES['ufile']['name']; $random_digit=rand(0000,9999); $new_file_name= $random_digit.$file_name; $path= "upload/".$new_file_name; if($ufile !=none) { $file_size=$HTTP_POST_FILES['ufile']['size']; if($file_size >= $limit_size){ echo "Your file size is over limit
"; echo "Your file size = ".$file_size; echo " K"; echo "
File size limit = 2 gb"; } else { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful
"; echo ""; } else { echo "Copy Error"; } } } ?>

Any help would be greatly appreciated.

Does a user login to your site? If they do, can you post the login code?

And also, please post your code inside of code or PHP tags. You can use the # or php button (as described in the IMPORTANT: message above the text-field when you make a new thread or reply to one).

A user logs into the site by the following code:

[php]<?php include "base.php"; ?>

Log in or Register
<?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?>
<h1>Member Area</h1>
 <p>Thanks for logging in! You are <b><?=$_SESSION['Username']?><b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p>

<ul>
    <li><a href="logout.php">Logout.</a></li>
</ul>

<?php

}
elseif(!empty($_POST[‘username’]) && !empty($_POST[‘password’]))
{
$username = mysql_real_escape_string($_POST[‘username’]);
$password = md5(mysql_real_escape_string($_POST[‘password’]));

 $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");

if(mysql_num_rows($checklogin) == 1)
{
	 $row = mysql_fetch_array($checklogin);
    $email = $row['EmailAddress'];
    
    $_SESSION['Username'] = $username;
    $_SESSION['EmailAddress'] = $email;
    $_SESSION['LoggedIn'] = 1;
    
	 echo "<h1>Success</h1>";
    echo "<p>We are now redirecting you to the member area.</p>";

echo “”;
}
else
{
echo “

Error

”;
echo “

Sorry, your account could not be found. Please <a href=“index.php”>click here to try again.

”;
}
}
else
{
?>

Member Login

Thanks for visiting! Please either login below, or click here to register.

<form method="post" action="index.php" name="loginform" id="loginform">
<fieldset>
	<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
	<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
	<input type="submit" name="login" id="login" value="Login" />
</fieldset>
</form>
<?php } ?>
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service