We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10076
    • 1,024 Posts
    Could you post the complete code you used.
    I need some registration form that will allow photo upload.
      • 28615
      • 14 Posts
      Hi Frank,

      I have not used the option(user registration with photo). I tried hard then it is not working. Instead, I made it such that user can add photo after registration. This I did by modifying the profile by putting snippet in the home pages.

      Manikandan
        • 10076
        • 1,024 Posts
        Hi Manikandan,

        so did you use the above for the registration snippet?

        Frank.
          • 28615
          • 14 Posts
          I used the code in post no#7 for adding photo names to user profile table
            • 20178
            • 82 Posts
            ok just trying to get my head around how you got this to work,

            once the user logged in did you use something like a formit call with a file upload and a hook to upload the users photo or did you do it all with the update profile call ?

            thanks,
              • 28615
              • 14 Posts
              I used the file upload form and the code as shown in post #7. No update profile call.
                • 20178
                • 82 Posts
                oh ok thanks you used the formit snippet - this is the way i was attempting to do it too, using the formit2file file snippet someone posted on here, but i would like to name with the call [[formit &hooks=’formit2file, emeil etc ]]
                
                
                i would like to name the file the same as the username and also put it in a folder with the name of the username too so i can pull these at a later date with the user profiles.
                
                 $userName = $modx->getLoginUserName();
                
                the line below doesnt 
                
                <?php
                // initialize output;
                
                  
                $output = true;
                
                // valid extensions
                $ext_array = array('pdf', 'txt', 'doc', 'docx', 'rtf', 'jpg',);
                
                // create unique path for this form submission
                  $userName = $modx->getLoginUserName();
                  $uploadpath = 'assets/uploads/$userName';
                 
                
                // you can create some logic to automatically
                // generate some type of folder structure here.
                // the path that you specify will automatically
                // be created by the script if it doesn't already
                // exist.
                
                // EXAMPLE:
                // this would put all file uploads into a new,
                // unique folder every day.
                // $uploadpath = 'assets/'uploads/'.date('Y-m-d').'/';
                
                // get full path to unique folder
                $target_path = $modx->config['base_path'] . $uploadpath;
                
                // get uploaded file names:
                $submittedfiles = array_keys($_FILES);
                
                // loop through files
                foreach ($submittedfiles as $sf) {
                
                  // Get Filename and make sure its good.
                  $filename = basename( $_FILES[$sf]['name'] );
                
                  // Get file's extension
                  $ext = pathinfo($filename, PATHINFO_EXTENSION);
                  $ext = mb_strtolower($ext); // case insensitive
                
                  // is the file name empty (no file uploaded)
                  if($filename != '') {
                      
                    // is this the right type of file?
                    if(in_array($ext, $ext_array)) {
                   
                      // clean up file name and make unique
                      $filename =  $userName($filename); // to lowercase
                      $filename = str_replace(' ', '_', $filename); // spaces to underscores
                      $filename = date("Y-m-d_G-i-s_") . $filename; // add date & time
                      
                      // full path to new file
                      $myTarget = $target_path . $filename;
                      
                      // create directory to move file into if it doesn't exist
                      mkdir($target_path, 0755, true);
                      
                      // is the file moved to the proper folder successfully?
                      if(move_uploaded_file($_FILES[$sf]['tmp_name'], $myTarget)) {
                        // set a new placeholder with the new full path (if you need it in subsequent hooks)
                        $modx->setPlaceholder('fi.'.$sf.'_new', $myTarget);
                        // set the permissions on the file
                        if (!chmod($myTarget, 0644)) { /*some debug function*/ }
                        
                          } else {
                        // File not uploaded
                        $errorMsg = 'There was a problem uploading the file.';
                        $hook->addError($sf, $errorMsg);
                        $output = false; // generate submission error
                      }
                      
                      } else {
                      // File type not allowed
                          $errorMsg = 'Type of file not allowed.';
                      $hook->addError($sf, $errorMsg);
                      $output = false; // generate submission error
                        }
                  
                  // if no file, don't error, but return blank
                  } else {
                      $hook->setValue($sf, '');
                  }
                
                }

                  • 3749
                  • 24,544 Posts
                  Use this instead:

                  $userName = $modx->user->get('username');


                  If the user is not logged in, the username will be "(anonymous)". The parentheses are part of the username in this one case.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 20178
                    • 82 Posts
                    thanks bobray i tried that but it is just creating a foleder called $username;

                    i want to create a folder with a unique name named after the user to place their image in,


                    $userName = $modx->user->get(’username’);

                    // create unique path for this form submission
                    $uploadpath = ’assets/uploads/$username’;


                    // you can create some logic to automatically
                    // generate some type of folder structure here.
                    // the path that you specify will automatically
                    // be created by the script if it doesn’t already
                    // exist.

                    // EXAMPLE:
                    // this would put all file uploads into a new,
                    // unique folder every day.
                    // $uploadpath = ’assets/’uploads/’.date(’Y-m-d’).’/’;




                    i also want to make the filename the username too say +image

                    // clean up file name and make unique
                    $filename = mb_strtolower($filename); // to lowercase
                    $filename = str_replace(’ ’, ’_’, $filename); // spaces to underscores
                    $filename = $userName . $filename; // add date & time
                      • 3749
                      • 24,544 Posts
                      Look at the core where you set the filename and see if you have ’$username’ where it should be just $username.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting