We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42146
    • 73 Posts
    I think this is more of a branch of http://forums.modx.com/thread/?thread=80740 i've been working on... which i have working code for 1 image to to upload to user profile extended data.

    Though i need to have multiple images... working on extending that code for multiples.

    iin the above post i fixed a issue where if a user didn't enter in a file, that then their old photo didn't get over written.

    i have no clue on proper syntax on how to do it for multiple images....

    not sure now to do that here....
    in the 
    // loop through files
    foreach ($submittedfiles as $sf) {
    
    functions
        //return exsisting photofields value
        if ($Photo_fields != '')
        {


    how to i make something like
    so that the variable name then becomes Photo_fields1, Photo_fields2, Photo_fields3 ....
        if ($Photo_fields . $sf!= '')
        {
    }


    $fields = $modx->user->getOne('Profile')->get('extended'); 
    // in the foreach loop
    $Photo_fields_index ='Profile_Photos' . $sf
    $Photo_fields = $fields[$Photo_fields_index];
    
    

    i'm guessing could do a array of
    if ($Photo_fields[$sf]!= '') 


    but i've been unable to get containers to work for extended data... then not sure how
    // get uploaded file names:
    $submittedfiles = array_keys($_FILES);
    then works.... with the foreach loop

    wish my php skills were better ;-/

      1. Don't put define functions within a loop
      2. Very basic arrays: http://www.tizag.com/phpT/arrays.php
      3. Simple PHP tutorials: http://www.tizag.com/phpT/
      4. Then read over this page: http://www.phptherightway.com/
      5. Maybe get a PHP book to learn more
      [ed. note: jgulledge19 last edited this post 11 years, 3 months ago.]
        • 3749
        • 24,544 Posts
        In order to help, we'd need to see all your code in one block.



          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
          • 42146
          • 73 Posts
          i ended up just having a different extended fields for each photo. instead of trying to do a array of photo's. was trying to turn the code i did from http://forums.modx.com/thread/?thread=80740&page=3 to work with user extended fields as a container / array, of profile images...

          I've just been trying to get a way for a user to upload multiple profile images, which then would be displayed in a slideshow. what i have now works, but if a user doesn't enter in a photo in the field the existing photo disappears. still don't have a way for a user to delete any of their images from their user directory.

          perhaps now that the site is online sekUserGalleries will work. the upload wouldn't work correctly with xammp, and the css it inserted would hose the rest of the sites css, was just to much work trying to hack up sekUserGalleries to make it work. already spent way to much time trying to get a user profile photo implemented.
          • There is nothing at all wrong with using functions in loops when applicable.

            When you have a form uploading files, you get the $_FILES array. You can loop through that $_FILES array something like this (taken from the PHP documentation):

            The form
            <h3>Pictures:</h3>
            <input type="file" name="pictures[]" />
            <input type="file" name="pictures[]" />
            <input type="file" name="pictures[]" />
            ...
            


            The PHP
            <?php
            foreach ($_FILES["pictures"]["error"] as $key => $error) {
                if ($error == UPLOAD_ERR_OK) {
                    $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
                    $name = $_FILES["pictures"]["name"][$key];
                    move_uploaded_file($tmp_name, "data/$name");
                   // Do whatever else you want to do about this particular picture here
                }
            }
            ?>
            
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
            • Quote from: sottwell at Jan 15, 2013, 06:25 AM
              There is nothing at all wrong with using functions in loops when applicable.

              When you have a form uploading files, you get the $_FILES array. You can loop through that $_FILES array something like this (taken from the PHP documentation):

              The form
              <h3>Pictures:</h3>
              <input name="pictures[]" type="file">
              <input name="pictures[]" type="file">
              <input name="pictures[]" type="file">
              ...
              


              The PHP
              <!--?php
              foreach ($_FILES["pictures"]["error"] as $key =--> $error) {
                  if ($error == UPLOAD_ERR_OK) {
                      $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
                      $name = $_FILES["pictures"]["name"][$key];
                      move_uploaded_file($tmp_name, "data/$name");
                     // Do whatever else you want to do about this
                     // particular picture here
                  }
              }
              ?>
              
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Technically you can put a function in a loop but this is not best practice see responses: http://stackoverflow.com/questions/12929501/running-a-loop-that-has-a-function-inside-it
                • That is dealing with defining a function inside of a loop, not defining a function then using that function inside of a loop.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                  • Quote from: sottwell at Jan 15, 2013, 01:23 PM
                    That is dealing with defining a function inside of a loop, not defining a function then using that function inside of a loop.

                    Correct, sorry I miss understood your comment on a quick read.