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


    In a php file, where there is upload process (not related to xenforo's upload process) I have this code:
        if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
            echo '{"status":"success"}';
    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:
      $user XenForo_Visitor::getInstance()->toArray();
    $userId $user['user_id'];

    move_uploaded_file($_FILES['upl']['tmp_name'], $userId.'/'.$_FILES['upl']['name'])){
    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:
    <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
                    <input type="file" name="upl" multiple />
                    <!-- The file uploads will be shown here -->

Share This Page