...

View Full Version : var is a link



Ludatha
01-26-2008, 04:46 PM
$upload_dir = 'D:\wamp\www\uploads\profile/.$_SESSION['username'].';
$upload_file = $upload_dir . basename($_FILES['userfile']['name']);

Hi, how can I get the username from the session to be used in the upload dir
.$_SESSION['username'].
Ive fiddled about with the code for ages and it doesn't seem to work 0.0

Mwnciau
01-26-2008, 05:50 PM
$upload_dir = 'D:\wamp\www\uploads\profile\\' . $_SESSION['username'];

Ludatha
01-26-2008, 06:42 PM
Thanks, at least I don't get an error message now, but something unexpected happened...

Say my name is ludatha on my site, logged in with a session.

When I upload the file, I wanted it to upload to
D:\wamp\www\uploads\profile\ludatha

What actually happens, is that my files get uploaded to
D:\wamp\www\uploads\profile\
and all the files get renamed to ludathathis_is_my_file_etc.png

How can I get it to put it in the directory of the user that is logged in?

here is the full php script I am using:


<?php
session_start();
require_once("header.php");

?>
<!-- C. MAIN SECTION -->
<div class="main">

<!-- C.1 CONTENT -->
<div class="content">

<!-- CONTENT CELL -->
<div class="content-cell-corner-top"></div>
<div class="content-cell">
<h1>Upload</h1>

<?php

if($loggedin==true)
{
$upload_dir = 'D:\wamp\www\uploads\profile\\'.$_SESSION['username'];
$upload_file = $upload_dir . basename($_FILES['userfile']['name']);

echo "<p>";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_file)) {
echo "File is valid, and was successfully uploaded";
} else {
echo "Upload ready to start";
}

echo "</p>";
echo "<form enctype='multipart/form-data' action='upload.php' method='POST'>
<input type='hidden' name='MAX_FILE_SIZE' value='512000' />
Send this file: <input name='userfile' type='file' />
<input type='submit' value='Send File' />
</form>";

}

if($loggedin==false)
{
echo"
<h3>You are not allowed to view this page, please login or register.</h3>
";
}


?>

</div>
</div>

<?php
require_once("footer.php");
?>

ukguy
01-26-2008, 07:03 PM
Can you try:

$upload_dir = 'D:\wamp\www\uploads\profile\\' . $_SESSION['username'] . '\\';

Ludatha
01-26-2008, 07:14 PM
Thank you, it has worked :)

One last thing, that is sort of the same subject.


echo '<img style="border: 1px solid #666666;" src="uploads/profile/'.$_SESSION['username'] .$file.'" width="200" height="110" /><br><br><b>thumbs/'.$file.'</b><br><br><br>';

['username']lllllllllllllllllllllllllllll.$file.

How do I add a / between those two?

ukguy
01-26-2008, 07:17 PM
Here you go :)


echo '<img style="border: 1px solid #666666;" src="uploads/profile/'.$_SESSION['username'].'/'.$file.'" width="200" height="110" /><br><br><b>thumbs/'.$file.'</b><br><br><br>';

Ludatha
01-26-2008, 07:20 PM
Thanks man :P

Maby we can work together on my little 'project' :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum