We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12793
    • 293 Posts
    Hi! I’ve a page where I will insert X documents to download... what solution do you suggest me for manage these documents??

    create x link in a specific folder .... or is there a specific plug-in? (or another solution)

    Thanks
      • 12793
      • 293 Posts
      isn’t there a solution?
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: il_dandi at Jun 12, 2010, 05:19 PM

        isn’t there a solution?
        Nothing like that exists currently; you will need to author such an Add-On to handle this. This could be done with a Custom TV Input Type (and possibly Output Type).
          • 3496
          • 101 Posts
          I would suggest storing the files in a specific directory and use something like the following (put the code in a snippet) to display the list:

          <?php
          //define the path as relative
          $path = "path to directory";
          $webpath ="the url you want to place before your filename/";
          //using the opendir function
          $dir_handle = @opendir($path) or die("Unable to open $path");
          
          echo "Directory Listing of $path<br/>";
          
          list_dir($dir_handle,$path);
          
          function list_dir($dir_handle,$path)
          {
              // print_r ($dir_handle);
              echo "<ol>";
              //running the while loop
              while (false !== ($file = readdir($dir_handle))) {
                  $dir =$path.'/'.$file;
                  if(is_dir($dir) && $file != '.' && $file !='..' )
                  {
                      $handle = @opendir($dir) or die("undable to open file $file");
                      echo "<li><a href='$webpath.$file'>$file</a></li>";
                      list_dir($handle, $dir);
                  }elseif($file != '.' && $file !='..')
                  {
                         echo "<li><a href='$webpath.$file'>$file</a></li>";
                  }
              }
              echo "</ol>";
              //closing the directory
              closedir($dir_handle);
          }
          ?>

          I found the code on this page: http://php.net/manual/en/function.readdir.php and I haven’t tested it...
          The code probably needs some changes to make it function better as a snippet:

          • for some hints, look at http://svn.modxcms.com/docs/display/revolution/Snippets
          • I would suggest using $modx->config[’base_path’] in stead of hard coding your sites main-directory
          • I would suggest to replace all "echo" statements by something like "$output.=" - and add "return $output" at the end of the snippet