We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4310
    • 2,310 Posts
    Thanks Breezer but still no new folders !
    Is it something to do with using MAMP ?
    I’ll try on a live server and see what happens.
      • 7231
      • 4,205 Posts
      MaxiGallery creates new folder with ID names, if it works in MAMP (it works on mine) that this plugin should work. Are you sure that your base_path is correct, try hard coding the path and see what happens.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 4041
        • 788 Posts
        A comment at the php.net site notes that the last trailing slash messes up the folder creation if the server is using php 5.1.6, maybe try removing it:
        $dir = $modx->config[’base_path’].$modx->config[’rb_base_dir’]."images/".$docid;

        http://us3.php.net/manual/en/function.mkdir.php#73848
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 4310
          • 2,310 Posts
          Tried hard coding the path, see commented out lines.
          PHP version is 5.2.6, but tried without the trailing slash.
          Tried on a live server.
          None worked, this is very strange!
          $e = &$modx->Event;
          $docid = $e->params['id'];
          $dir = $modx->config['base_path'].$modx->config['rb_base_dir']."images/".$docid;
          //$dir = "/Aplications/MAMP/htdocs/westcoastestates/assets/images/19";
          //$dir = "http://localhost/westcoastestates/assets/images/19";
          $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":
          
            $old_umask = umask(0);
                  mkdirs($dir,$folder_permissions);
            umask($old_umask);
            break;
            
            default: "";
          
            return;
          }
            • 4310
            • 2,310 Posts
            Victory is mine, well yours, to be fair  smiley
            Turns out Breezer’s script was happily creating folders here :
            westcoastestates/Aplications/MAMP/htdocs/westcoastestates/assets/images/’.$docid.’
            By removing
            $modx->config['base_path'].
            from the $dir variable it’s now creating in the westcoastestates/assets/images/ folder.
            Many thanks to everyone, special thanks to Breezer.
            Now I’ll have to add an IF statement to limit it to certain templates.
            Final code that creates a new folder only for templates 5 or 3 :
            $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'] == 5 || $_REQUEST['template'] == 3)
            {
              $old_umask = umask(0);
                    mkdirs($dir,$folder_permissions);
              umask($old_umask);
              }
              break;
              
              default: "";
            
              return;
            }