Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: var is a link

  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    var is a link

    PHP Code:
    $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

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $upload_dir 'D:\wamp\www\uploads\profile\\' $_SESSION['username']; 

  • Users who have thanked Mwnciau for this post:

    Ludatha (01-26-2008)

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    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 Code:
    <?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"); 
    ?>

  • #4
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    Can you try:
    PHP Code:
    $upload_dir 'D:\wamp\www\uploads\profile\\' $_SESSION['username'] . '\\'

  • Users who have thanked ukguy for this post:

    Ludatha (01-26-2008)

  • #5
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Thank you, it has worked

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

    PHP Code:
    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?

  • #6
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    Here you go
    PHP Code:
    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>'

  • #7
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Thanks man :P

    Maby we can work together on my little 'project'


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •