We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25519
    • 265 Posts
    Hi

    I’m building a site for a Chartered Surveyor company and they need a Property Details/Particulars document download link for most of the properties in the site. The doc formats will be either Word or PDF. For the record, Each property is a seperate document (resource) and all are rendered via ditto.

    Ideally, for each property I would like the content editor to be able to upload a Word/PDF file to link to via the resource manager, just like adding a new image. Editor then creates text hyperlink to the file. End user downloads the file via the text link.

    Is this feasible?

    Thus far I can’t see how to allow the Editor to manage uploads for these types of files in the MODx/Tiny MCE management interface - looked at the obvious place: Tools > Config > Custom content types: but what I need is in the list by default, plus that doesn’t seem to answer the question here.

    Can someone please enlighten me?

    Thanks in advance
      • 3749
      • 24,544 Posts
      Tools | Config | File Manager Tab | Uploadable File Types ?

      doc is there but you’ll need to add pdf.

      BTW, I have users log on in the front end and upload the files using the FileUpload snippet (at least I think I do, it’s been a while since I set it up).
        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
        • 25519
        • 265 Posts
        Cheers BobRay

        This lead me to look deeper into the extra/snippets lists and can see the handy file upload tools there, only prob is I’m using Evolution 1.0 for this site and the snippets appear to support up to 0.9.6. - otherwise I can see this base covered. Thanks for that info.

        Otherwise, I think i’ll approach it all rather differently for generating the text link to the uploaded file, here’s the plan ...

        Add a tv, say [*download-particulars*] and have this show/hide with PHX - this tv would be a text field which only requires the file name and this serves as the final part of the file path to ’assets/files/[*download-particulars*]’ - so the link will be there, but only visible if a file has been uploaded.
        I’ll hit this later and feedback with results.

        Otherwise, I can’t see a simple way for the content editors to interface with ’assets/files/’ to create this link via the content editor - unless anyone else knows how to do this ... huh

        Thanks
          • 3749
          • 24,544 Posts
          The upload snippet(s) *should* work with 1.0 but you never know until you try.

          I use a fairly simple snippet on the download page that reads the directory, sorts the files, and generates the links. If you don’t care about the order, I think a Template Variable with the @DIRECTORY binding would do it too.
            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
            • 25519
            • 265 Posts
            I’ll give the upload snippets a try, nothing ventured ...

            I can’t use a whole downloads page, these need to be on a page/property specific basis, ie the related download on the specific property page. But it’s good to be enlightened about the snippet, thanks.

            re using a Template Variable with the @DIRECTORY binding, this sounds like a good solution (at least a good experiment!) - poss it could be wrapped into Ditto and sorted in ASC order? I’ll give it a go, but his will have to wait.

            Cheers
              • 3749
              • 24,544 Posts
              Just a thought: If you could compute the directory and filename of the file(s) to be downloaded based on the name of the document (or any other field, including a TV), a fairly simple snippet could still do the link for you.
                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
                • 25519
                • 265 Posts
                See your logic there but my php is not up to the job - any takers??? (unless this has already been written and listed)
                  • 3749
                  • 24,544 Posts
                  Quote from: rootsdiv at Oct 02, 2009, 04:13 AM

                  See your logic there but my php is not up to the job - any takers??? (unless this has already been written and listed)

                  If you describe exactly what you need, someone may chime in with some code to try.
                    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
                    • 25519
                    • 265 Posts
                    Hi, Sorry for the delayed response
                    compute the directory and filename of the file(s) to be downloaded based on the name of the document (or any other field, including a TV)
                    I’d say what you stated there pretty much sums it up, but applied to a template in a Ditto call, where placeholder/tv [+supporting-document+] would automatically add the supported doc for that given property.

                    Obviously the documents would need a strict naming system, ie the same as the [+pagetitle+] and located in the /assets/files/ directory.

                    That way any script would just look at [+pagetitle+] and automatically search for the same name as either .doc, .docx or .pdf in the correct place, and render the document link depending on whether there is a supporting document.

                    This could be given a conditional - via PHx possibly - and the document link only appear if there is a supporting document.

                    That’s the logic, but I couldn’t write it in php! - unless the whole sounds feasible via simply a PHx statement ...

                    Thanks
                      • 3749
                      • 24,544 Posts
                      This is off the top of my head and untested (I’m assuming that there might be more than one associated document):

                      Snippet Call in doc or template:
                      <div class="FileDownload">[!GetFiles? &docName=`[*pagetitle*]` !]</div>


                      GetFiles snippet:

                      <?php
                      if (empty($docName)) {
                         return '$docName is empty<br />';
                      }
                      $dir = MODX_BASE_PATH . 'assets/files/' . $docName . '.*';
                      
                      $filesArray=glob($dir);
                      
                      $output = '';
                      
                      /* did we get any? */
                      
                      if (count($filesArray) ) {
                      
                           foreach($filesArray as $file) {
                             /*  echo 'doing one<br />'; */
                              $info = pathinfo($file);
                      
                             /* PHP4 Compatibility */
                              if(!isset($info['filename'])){
                                      $info['filename'] = substr($info['basename'], 0,strpos($info['basename'],'.'));
                              }
                      
                         
                              $output .= '<a href="' . MODX_BASE_URL . $info['filename'] . '.' . $info['extension'] .  '">' . $info['filename'] . '.' . $info['extension'] . '</a><br />';
                      
                          }
                      }return $output;
                        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