We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36926
    • 701 Posts
    Hi,

    Has anyone successfully adapted the webloginpe to allow multiple images? I can’t seem to find any post of anyone actually doing this.

    I think what i may need to do is upon creating an account a folder is created with the name of each username and all images are uploaded to the individual username folders. My php isnt great but managed to write a line of code that creates a folder with the name of the logged in webuser. Anyone have an idea how and where i could insert this code to run when the username is confirmed?

    The code:

    $currentWebUser = $modx->getWebUserInfo($modx->getLoginUserID());
    $currentUserName = $currentWebUser['username'];
    $webUserDir = $modx->config['base_path'].'assets/webusers/'.$currentUserName;
    
    
    $result = mkdir($webUserDir, 0777);
       if(!$result) {
          echo "Error: Couldn't create the directory!";
    
       }


    Any help on uploading multiple images and/or creating users directorys would be much appreciated.

    Many Thanks

    Ben
      • 4310
      • 2,310 Posts
      Ben,
      I have used a file browser CKFinder on the webloginePE edit profile page to enable uploads to a folder with a number that matches the web users id. That coupled with your create folder script used when the account is created should do it.
        • 36926
        • 701 Posts
        Thanks for that, was it just a case of adding this within the edit profile template? How familiar are you with the webloginpe code as i’m not that sure where i could place the folder creation code to be executed once the user has been allocated a user name that hasn’t been taken.

        Thanks

        Ben
          • 4310
          • 2,310 Posts
          I’ll try and have a look at integrating it into the register part of the webloginpe.class.php file, maybe over the weekend.
          The project I was using the image upload feature for already had their registered users, so I created the folders manually.
            • 36926
            • 701 Posts
            Thanks that would be great.

            Ben
              • 36926
              • 701 Posts
              Ok, started trying to work were i should add the code i had to create a new directory for a new user using their username. I looked thru the code i guessing it’s going to have to go probably just after the user has been successfully added to the database.

              I’ve add the following to line 601 of webloginpe.class.php just after the if (!$createNewUser);


              		$webUserDir = $modx->config['base_path'].'assets/comp/'.$username;
              		$result = mkdir($webUserDir, 0777);
                 if(!$result) {
                    echo "Error: Couldn't create the directory!<BR>";
              
                 }

              I’m thinking i’d probably better of using the $key (which i’m guessing is the unique id for a user that will never change) variable as apposed to $username, as if the user changes their user name (not sure if webloginpe allows this) then a new user could then sign up using the old username.

              If anyone looks at this and see i’m going about this completely wrong, please let me know.

              Many Thanks

              Ben
                • 4310
                • 2,310 Posts
                You probably need to add your code after :
                	$key = $modx->db->getInsertId();
                		$NewUser['internalKey'] = $key; // pixelchutes

                To use the $key (internalKey) value for the folder ID.
                  • 36926
                  • 701 Posts
                  Still having problems with this.

                  I want to modifying the snippet slightly so the user image is uploaded to my new directory. But hit a slight problem. I think what is happening is the image is being uploaded to the folder before the folder is actually created as if i create the folder before hand the image uploads fine to that directory.

                  The code i have modified is on line 2600
                  // Output
                  $userImageFilePath = $modx->config['base_path'].'assets/snippets/webloginpe/userimages/'.str_replace(' ', '_', strtolower($currentWebUser['username'])).$ext;


                  I’ve changed it to:
                  $newImageLocation = $modx->config['base_path'].'assets/comp/'.str_replace(' ', '_', strtolower($currentWebUser['username']));
                  // Output
                  $userImageFilePath = $newImageLocation.'/'.str_replace(' ', '_', strtolower($currentWebUser['username'])).$ext;

                  I had to re define the image location folder as the variable $webUserDir i had defined earlier on line 601 wasn’t being recognised. Not sure what I need to do be able to use them here as well. I also know i have to changed the other lines of code for the URL ect but just want to get this working first.

                  I’ve also tried adding the code to create new directory just above this code but still no luck. I thought PHP processed code in order as in if the dir creation is first then that will be created then it would do the next line of code which is to upload the image.

                  Is there no one out there who has successfully modified webloginpe to allow multiple images/files.

                  Ben