We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28615
    • 14 Posts
    I am using Revolution 2.0.4 and Login Add-on for user management.
    I am using the following html code in Registration form to add user photo (image) in the User profile.


    <label for="photo">[[%photo]]
                <span class="error">[[+error.photo]]</span>
            </label>
           <li> <input type="file" name="photo:optional" id="photo" value="[[+photo]]" /></li>
    


    When I am accessing the image inside the documents using [[+user.photo]], the image is not rendered. Is there any other way to do this?
      • 13036
      • 8 Posts
      I have tried this as well. I used [[+photo]] instead, but all I have gotten to display is the actual file name. ie: Koala.jpg instead of a picture of a Koala. Any help out there?
        The most dangerous type of bear
        • 28615
        • 14 Posts
        That photo field option in registration form is not working. I did i different way. I removed the image uploading options from registration form and put it in side the web pages. Follow the below link to know more about the details.

        http://modxcms.com/forums/index.php/topic,57256.msg327787.html#msg327787

        Manikandan
          • 17855
          • 43 Posts
          Hi - I’m just looking for the same functionality, I’ve read the linked post (havent tried it yet though)

          That photo field option in registration form is not working.

          Just looking at previous post, is there a photo field option in Login? I haven’t seen it in the docs.

          Just checking I’m not missing something - Jim
            • 20178
            • 82 Posts
            I too would like to be able to upload and store a photo and perhaps a file did anyone find a work around for this?

            i think im going the direction of having a seperate formit call on the user update profile page where they can upload a photo and perhaps a pdf too, i found the useful snippet formit2file;
            this works fine but is it possible to perhaps add data about the image to the user database?

            the code below creates a unique folder for the image file ;

            i would like the folder to be the username so each image is in the username folder ; but the attempt below doesnot work;

            $userName = $modx->getLoginUserName();
            $uploadpath = ’assets/uploads/$userName’;

            i would also like the user name to be the file name of the image too say +pic or something; but below doesnt work either

            $filename = $userName($filename); // to lowercase
            $filename = str_replace(’ ’, ’_’, $filename); // spaces to underscores
            $filename = date("Y-m-d_G-i-s_") . $filename; // add date & time



            <?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, '');
              }
            
            }
            
              • 7243
              • 21 Posts
              Bump...has anyone found a way to integrate directly with registration so posts can reflect users? SOrry about bumping this, but my post on this matter, after viewing this thread was left unanswered so, as an act of desperation.....
              • I think I did it ))

                But on update profile)) I use preHook snippet
                  modx and ecommerce pro
                • @modx.customize: can you post details of how you did it? thanks
                  • There is a from on register and it can work with prehooks which can be any php code. As far as I remember in that case I wrote the code for user's profile to have a setting with photo uploaded via this registration multipart form data

                    I surely do not keep this code saved, sorry.. but hope the idea is clear..
                      modx and ecommerce pro