We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Can a media source be outside of the web root? Or would such a beast require a custom source type?
      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
      • 3749
      • 24,544 Posts
      When I tried it, I found that the standard file Media Sources are automatically prefixed with the web root path. I didn't try creating a custom MS, though.

      Such a thing would be *really* handy for static elements during development.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
      • I would use it for static resources for a downloadables (.pdf, .doc and .zip) repository. Static resources can be manually linked to external files, but a media source would make things soooo much easier.
          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
          Didn't try fileMediasources outside the web-root.
          I think it should be possible somehow.
          Need to dig into the mediasource-code again, to find a solution.

          Perhaps the opengeeks know an answer out of their head.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
          • You will have to use absolute path settings for the Media Source, but it should definitely work with the exception of thumbnails in the Media Browser and URL access to the files (since those won't apply if the files are not within a web accessible path).

            BTW, you can use Static Elements without the overhead associated with Media Sources as well. When you do not select a Media Source, Static Elements accept absolute paths, as well as paths relative to your components_path Setting (defaults to MODX_CORE_PATH . 'components/'). You can override this path specifically for Static Elements without affecting your components_path by creating a System Setting for element_static_path (similar to resource_static_path for Static Resources). [ed. note: opengeek last edited this post 11 years, 6 months ago.]
            • 1. Create new Media Source:
              Name: PDF
              Description: PDF download repository
              Source Type: Filesystem

              2. Update Media Source:
              basePath: /blah/blah/pdf/
              basePathRelative: No

              allowedFileTypes: pdf

              The Media Source shows up in the File Manager, and can be assigned, but nothing shows in it and when trying to upload in various applications I get various errors that it's not a directory (File Manager upload) or that it's not writable (MIGX AJAX upload). I've set the directory and the files uploaded via SFTP in it to 777.

              Question: How does one determine the path of the installation in the MODx Cloud? I get it from the phpinfo() view, or the various config files, but in Evo it was a basic part of the system info.


                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
              • @opengeek - I really need to use Media Sources, since it's actually using a dynamic source via a snippet in the basePath and baseURL that works wonderfully within the web root - thanks to Bruno17.

                With this snippet, a directory in a given path is used based on the resource ID or pagetitle. If the path isn't found it can be created.

                [[migxResourceMediaPath? &pathTpl=`assets/productdocuments/{id}/`]]


                <?php
                $pathTpl = $modx->getOption('pathTpl', $scriptProperties, '');
                $docid = $modx->getOption('docid', $scriptProperties, '');
                $createfolder = $modx->getOption('createFolder', $scriptProperties, false);
                $path = '';
                $createpath = false;
                
                if (empty($docid) && $modx->getPlaceholder('docid')) {
                    // placeholder was set by some script
                    $docid = $modx->getPlaceholder('docid');
                }
                if (empty($docid)) {
                
                    if (is_Object($modx->resource)) {
                        //on frontend
                        $docid = $modx->resource->get('id');
                    } else {
                        //on backend
                        $createpath = $createfolder;
                        $parsedUrl = parse_url($_SERVER['HTTP_REFERER']);
                        parse_str($parsedUrl['query'], $parsedQuery);
                
                        if (isset($parsedQuery['amp;id'])) {
                            $docid = $parsedQuery['amp;id'];
                        } elseif (isset($parsedQuery['id'])) {
                            $docid = $parsedQuery['id'];
                        }
                    }
                }
                
                if ($resource = $modx->getObject('modResource', $docid)) {
                    $path = str_replace('{id}', $docid, $pathTpl);
                    $path = str_replace('{pagetitle}', $resource->get('pagetitle'), $path);
                    
                    $fullpath = $modx->getOption('base_path') . $path;
                
                    if ($createpath && !file_exists($fullpath)) {
                        mkdir($fullpath, 0755, true);
                    }
                
                    return $path;
                }


                [ed. note: sottwell last edited this post 11 years, 6 months ago.]
                  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
                • I got it! The relative basePath is ../home/pdf/ (in the Cloud)

                  Gotta love good old trial-and-error! And of course an SFTP client that shows all the paths to everything.
                    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
                  • Oops... now the File Manager and the MIGX grid seem to be working fine, but when clicking on the link to the static resource's page... the server can't find the file.

                    Does this mean that a static resource is just a wrapper for a direct link to a file, and isn't actually processing a file for download?

                    A MODx Static Resource can represent any file on your webserver (permissions permitting)

                    Apparently this should actually read "any file within your web root", unless I've missed something.
                    [ed. note: sottwell last edited this post 11 years, 6 months ago.]
                      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
                      what we need is the path, not only the filename as content for our static resource.
                      tried this:
                      ../home/pdf/testing.pdf as content and this seems to do it.

                      shouldn't be a big thing to get the path into our file-selectbox.

                      we need this mediasource only for the ajax-uploader and for the fileselectbox in the backend. [ed. note: Bruno17 last edited this post 11 years, 6 months ago.]
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!