We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47832
    • 3 Posts
    Is there a way to handle this in modx?

    As an example, say I want to provide downloadable documents as PDF's to my users and I want to include information such as Author, Document Title, a summary or description of the content and so on.

    So far, all the file download mechanisms and extras I've come across seem to derive information from the file system itself, details like file size, file name, date created etc (although I see filedownload_r storing download counts in a database table).

    Ultimately I'd like to allow content managers to upload files and manage all the associated file details. Is this possible using core modx functions or an existing extra?

    thanks,

    (Using modX Revo 2.2.14-pl)
      • 3749
      • 24,544 Posts
      I don't know of an extra that does this (though there may be one). You could limit users to uploading a single file at a time an add a form for metadata on the page, then use either FormIt or a custom snippet to save the metadata somewhere - like in a file called filename.metadata, or in TV's on a file description page for each file, or in a chunk called filenamemetadata.
        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 did something close to this last year. To have the metadata you might look into creating Static Resources with appropriate fields (maybe TVs) for Author, etc. Then set a getResources call to aggregate the Static Resources to a specific page.

        The beautiful thing is that you can have the files of the static resources stored outside root.

        Follow links:
        http://forums.modx.com/thread/?thread=86908&page=1
        http://forums.modx.com/thread/?thread=86084&page=1
        http://forums.modx.com/thread/86939/media-resource-basepath-web-root-setting#dis-post-479021
        http://bobsguides.com/revolution-permissions.html
        • Indeed, Static Resources with a relevant Resource Type are the way to go. It allows all kinds of metadata, as well as search based on those resource fields, and it allows security of your files since they can be outside of the web root, and whether they are in the web root or not only the URL to the static resource is shown, not any links or URLs to the file itself.

          I'm working on a snippet? CMP? to generate Static Resources for existing files. It will generate Static Resources for all of the files of a given type in the given path. It is intended to be used in conjunction with any necessary custom Content Types and a Media Source. The filename will be used for the pagetitle and (minus the extension) for the alias. The Content Type will be determined by the file extension, which will be compared to the available Content Types. Binary will be set by default for specific content types, such as PDF. Of course, once the Static Resources are generated, they can be moved around and edited as needed in the Tree.

          I'm also working on two other closely related projects, an SFTP Media Source driver, and then a new Static Resource object that works with Media Sources - modSourcedStaticResource (unless somebody does something about having Static Resources work properly with Media Sources first...)
            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
            Its also possible to use MIGX or MIGXdb to get, what you want.

            Currently I'm working on a project, where redactors upload images for news into an upload-directory by ftp with defined file-names.
            I have a snippet, which is running in the MIGX-TVs input-options:
            @EVAL return $modx->runSnippet('sn_News_getImages_for_migx');
            


            the snippet is searching for files with the prefix of the pagetitle, of the currently edited resource.
            It creates a file-directory with the same name as the pagetitle, imports the images to that directory and imports them into the MIGX-TV, where they can add additional informations to each image.

            The snippet does currently look like that:

            $docid = 0;
            
            if (isset($_REQUEST['object_id'])) {
                //in CMP
                $docid = $_REQUEST['object_id'];
            } elseif (is_object($modx->resource)) {
                //in resource-manager
                $docid = $modx->resource->get('id');
            }
            
            
            $id = $modx->getOption('id', $scriptProperties, $docid);
            
            if (empty($id)) {
                return '';
            }
            
            if ($doc = $modx->getObject('modResource', "$id")) { // Verbindung id mit Resource
                $pagetitle = $doc->get('pagetitle'); // Auslesen des Resourcen Titles
            }
            
            $uploadpath = $modx->getOption('pfad', $scriptProperties, 'inhalt/mediaRedaktion/bilder_news_upload');
            $uploadpath = $modx->getOption('base_path') . $uploadpath;
            
            $imagepath = $modx->getOption('pfad', $scriptProperties, 'inhalt/mediaRedaktion/bilder_news');
            $imagepath = $modx->getOption('base_path') . $imagepath . '/' . $pagetitle;
            
            /* AUSLESEN DER BILDER IM UPLOAD VERZEICHNISS
            ------------------------------------------------------ */
            
            $alledateien = scandir($uploadpath); // liest alle Dateien in dem Verzeichnis aus, das mit der Variable &pfad an das Snippet uebergeben wurde
            $i = 0; // $i zum Numerieren der Bildnamen im Array $bilder mit 0 starten
            $bilder = array(); // Array $bilder für die Bildnamen definieren
            foreach ($alledateien as $bildname) { // Ausgabeschleife, der Dateiname wird jeweils in $bildname uebergeben
                if (preg_match("/$pagetitle/", "$bildname")) { // wenn im Bildnamen der Pagetitle enthalten ist...
                    $bilder[$i] = $bildname; // ... wird der Bildname unter der aktuellen Nummer $i in das Array gepackt
                    $i++; // Dann wird $i eins hochgezaehlt
                }
            }
            $anzahl = count($bilder);
            
            if (!$anzahl) {
                //keine Bilder gefunden
                // evtl. vorhandenes Verzeichnis entfernen
                if (file_exists($imagepath)) {
                    if (!@rmdir($imagepath)) {
            
                    }
                }
                return '';
            }
            
            /* BILDORDNER ERSTELLEN
            ------------------------------------------------------ */
            if (!file_exists($imagepath)) {
                if (!@mkdir($imagepath, 0755, true)) {
                    $modx->log(MODX_LOG_LEVEL_ERROR, sprintf('[sn_News_getImages_for_migx]: could not create directory %s).', $imagepath));
                }
            }
            
            
            /* GEFUNDENE BILDER IN EIGENEN ORDNER JE NEWS VERSCHIEBEN
            ------------------------------------------------------ */
            foreach ($bilder as $bild) {
                $source = $uploadpath . '/' . $bild;
                $target = $imagepath . '/' . $bild;
                rename($source, $target);
                unlink($source);
            }
            
            /* AUSLESEN DER BILDER IM NEWS-IMAGE VERZEICHNIS
            ------------------------------------------------------ */
            
            $alledateien = scandir($imagepath); // liest alle Dateien in dem Verzeichnis aus, das mit der Variable &pfad an das Snippet uebergeben wurde
            $i = 0; // $i zum Numerieren der Bildnamen im Array $bilder mit 0 starten
            $bilder = array(); // Array $bilder für die Bildnamen definieren
            foreach ($alledateien as $bildname) { // Ausgabeschleife, der Dateiname wird jeweils in $bildname uebergeben
                if (preg_match("/$pagetitle/", "$bildname")) { // wenn im Bildnamen der Pagetitle enthalten ist...
                    $bild = array();
                    $bild['image'] = $bildname;
                    $bild['id'] = $bildname;
                    $bilder[$i] = $bild;
                    $i++; // Dann wird $i eins hochgezaehlt
                }
            }
            $anzahl = count($bilder);
            
            return $modx->toJson($bilder);
            
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!