1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting user id in a php file

Discussion in 'XenForo Development Discussions' started by Dadparvar, Apr 16, 2016.

  1. Dadparvar

    Dadparvar Well-Known Member

    Hi,

    In a php file, where there is upload process (not related to xenforo's upload process) I have this code:
    Code:
        if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
            echo '{"status":"success"}';
            exit;
        }
    That will cause the file be uploaded in "uploads" folder.
    How to change it, so that when user with user_id 1 upload the file, then it be uploaded in folder "1" and if user 2 did, then in "2" and so...

    I tested this code, bu now worked:
    PHP:
      $user XenForo_Visitor::getInstance()->toArray();
      
    $userId $user['user_id'];

        if(
    move_uploaded_file($_FILES['upl']['tmp_name'], $userId.'/'.$_FILES['upl']['name'])){
            echo 
    '{"status":"success"}';
            exit;
        }
    Thanks in advance
     
  2. Dadparvar

    Dadparvar Well-Known Member

    Also this is the codes I used in template to connect to this php file to add the upload box to a page:
    Code:
    <xen:require css="dadparvar_profilemusic_uploader.css" />
    <form id="upload" method="post" action="styles/default/dadparvar/profilemusic/songs/upload.php" enctype="multipart/form-data">
                <div id="drop">
                    Drop Here
    
                    <a>Browse</a>
                    <input type="file" name="upl" multiple />
                </div>
    
                <ul>
                    <!-- The file uploads will be shown here -->
                </ul>
    
    </form>
    
     

Share This Page