We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I'm trying to work with Media Sources. I cannot find any documentation at all on how they actually work or how to work with them. The API docs are, as usual, somewhat less than helpful.

    So far I have managed to get to this point, on suspicion that the source needs to be initialized before it can be used:
    $mediasource = $modx->getObject('modMediaSource',array(
           'name' => 'files' ));
    $mediasource->initialize();
    $sourceBasePath = $mediasource->getBasePath();
    

    Now, according to the API, there are two functions that seem like they should provide a list of files and folders in the source, getObjectsInContainer( string $path ) and getContainerList( string $path ). However, all these do is return empty arrays instead of an array of files and folders, as expected.

    So the question is, now that I have an initialized source and know its basePath, how do I go about getting a list of files and directories?
      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
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      So I can easily enough roll my own file lister, even a recursive one, using PHP scandir() and foreach() functions. But what are the API functions good for, then?
        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
        • 4172
        • 5,888 Posts
        As far, as I can remember you will need most of the steps done, for example, like in that processor
        https://github.com/modxcms/revolution/blob/develop/core/model/modx/processors/browser/directory/getfiles.class.php#L39

        before you can use these API - functions
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!