We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7637
    • 11 Posts
    What I'm trying to accomplish (in my "assets/images" directory) is create a hierarchy of folder based on my site hierarchy: one folder for each document (small site) and sub-folders for children documents.

    Is there anything out there that does this already? I'm comfortable around modx but nowhere near the coding genius to create my own solution.

    Thanks for any help or direction!
      • 4310
      • 2,310 Posts
      Here's a plugin that on doc form save, creates a folder named as the doc id in assets/images/ if the template id = 9
      $e = &$modx->Event;
      $docid = $e->params['id'];
      $dir = $modx->config['rb_base_dir']."images/".$docid;
      $folder_permissions = octdec($modx->config['new_folder_permissions']);
      
      function mkdirs($strPath, $mode){ // recursive mkdir function
              if (is_dir($strPath)) return true;
              $pStrPath = dirname($strPath);
              if (!mkdirs($pStrPath, $mode)) return false;
              return @mkdir($strPath);
      }
      
      switch ($e->name) {
      case "OnDocFormSave":
      if($_REQUEST['template'] == 9)
      {
        $old_umask = umask(0);
              mkdirs($dir,$folder_permissions);
        umask($old_umask);
        }
        break;
        
        default: "";
      
        return;
      }

      It might start you in the right direction
        • 7637
        • 11 Posts
        Thank, I'll have to take some time and work through what I can figure out. Looks like a starting point though.