On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • This is a little snippet I wrote to display a table of files from a folder for downloading. All you have to do is pass the relative path of the folder, and it will return the table. I don’t like to use tables but thought it was the easiest way to display the information. It shows the file name, file size, the date, and a download link for each file. There are other parameters in there for setting style classes.

    Just copy the contents of the attached file into a snippet called FileDownload.

    If you have any ideas on how to make this better, feel free to send me an email or post it here.

    Kyle

    You can find more information on this snippet and see it working go here:

    http://www.muddydogpaws.com/notebook/file-download-snippet

    To see the directory browsing feature go here:

    http://www.muddydogpaws.com/download-test

    For style information and examples read this post:

    http://modxcms.com/forums/index.php/topic,3124.msg30554.html#msg30554



    *******Update: 05/12/06**********
    Updated so links validate as valid xHtml 1.0 transitional.

    *******Update: 05/08/06**********
    There was an error with the directory browsing if you are not using friendly urls. It has been fixed in the package below.

    *******Update: 05/01/06**********
    I have updated the code to include the directory browsing posted by Roc. I modified the code a little so that it works with the download counting as well. I also cleaned up my code to make things hopefully a little faster. The new zip is attached below with full instuctions in the readme.



    *******Update: 03/22/06**********
    Added the ability to only list a single file. There is a new parameter named getFile for this, in the snippet call you add the following if you only want the file example.txt to show: &getFile=`example.txt`.



    *******Update: 03/18/06**********
    There was an error in the file download.php, I have updated the file in the zip.



    ***** Update 03/08/06 ******
    I have put an updated version of the file download snippet out. This time there is a zip file for you to download. You can now track how many times a file has been downloaded and display it on the page. You can also use the snippet multiple times on the same page.

    Due to the changes in this version I have a few extra files that need placed in a folder (filedownload) in your snippet directory. There are full instructions in the readme.txt file in the zip.


    ***** Update 03/06/06 ******
    I have updated the FileDownload Snippet with some new features.

    You can specify which user groups can download the files.
    You can specify the sort order (name,type,size,date) and ascending or descending
    You can set which file types you would like to show, i.e. if you only want png files to show in the list.
    You can give a user group the ability to delete files. There is a new placeholder for this [+delete+] for the template.


    ***** Update 03/02/06 ******
    I have posted a newer version again today. The following changes have been made:

    The description code has been changed so it will work with php4.
    You can have filetype images for different filetypes. There is documentation in the snippet on how to use this.
    I have made the error messages work better.

    ***********************************************************


    ***** Update 03/01/06 ******
    After seeing the comments here and some of the work done, I have updated the FileDownload Snippet.

    I added the code for using a template, thanks to Robin for getting that going.
    I also added the ability to get a description from a chunk (Great idea Susan), so you can update the info in the manager.
    The ability to have alternating odd/even row highlighting is still there as well.

    I also uploaded examples of the display template and the description chunk.

    So enjoy.

    *******************
    • Thanks Kyle ! And congrats about your first MODx snippet grin

      I’ll give it a test run and report smiley
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
      • Quote from: kjaebker at Feb 28, 2006, 05:19 PM

        If you have any ideas on how to make this better, feel free to send me an email.

        Not sure how, but would be awesome if it could have a comment about the file, like a description added.
          [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
          Admin Sandbox Login: sandbox Password: castle
        • Thanks, I may have use for just this kind of snippet. I was just about to start doing a download page... smiley

          Quote from: Briggsy at Feb 28, 2006, 08:30 PM

          Not sure how, but would be awesome if it could have a comment about the file, like a description added.
          I would also like this feature. Not sure if it would be overkill, though.
          • I thought about adding a comment for each file but was not sure where it would get stored. If I can find a way to add that I will update the code. In windows there is a place to store comments about a file so it may be easy to pull it from there. I will look into it.

            Kyle
            • +1 on the comment thing, good catch !

              Couldn’t you use a TV to store the comment and add it as an install instruction to create a TV usable by the template of the download page (no coder here, just conceptualizing... maybe that’s plain undoable or not convenient) ?
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
              • Hm... Some sort of TV would be possible, I guess. But it’s not much easier than doing a static download page and linking to the files.

                I was thinking something like simple text files alongside the downloadable content. Maybe the snippet could have a variable for the text file extension so that it would be easy to omit them from the listing itself.

                Or we could leave this Snippet as it is, since it’s probably pretty good at what it does. smiley
                • How about have just 1 file in the directory with the comments for all files within this one file.
                  It could be just a csv file with (filename,comment,numdownloads) etc.

                  Comments could be split using | characters etc

                  ie myfile.txt,this is a text file,im a comment|another comment,25
                  myfile2.txt,another text file,comment for myfile2,12

                  or for more items, an xml file should be ok

                  <file name="myfile.txt" numdownloads="25">
                  <description>this is a text file</description>
                  <comment author="a user">comment</comment>
                  <comment author="another user">another comment</comment>
                  </file>
                  <file name="myfile2.txt" numdownloads="12">
                  <description>another text file</description>
                  <comment author="username">comment for myfile2</comment>
                  </file>

                  • And you might take advantage of @FILE @binding maybe ?
                      .: COO - Commerce Guys - Community Driven Innovation :.


                      MODx est l&#39;outil id
                    • The snippet is fine for what it does, but be cool to see it extend into a more flexible snippet. of course its easy for me, a non programmer to say smiley

                      I agree with having a separate "description file" in the same directory which it looks up. Where no description is found, it leaves it blank. Don’t recommend using windows information as it wont work on Linux.

                      It would be cool to have placeholders for each filed, so users can place them where they want in the table, or even what information they want. So if the don’t want the date, don’t use that placeholder. The order of placholders determines the order they are put in columns.

                      So you can have something like this http://www.emanz.ac.nz/resources.html but in a table of some sort with alternating row colours, which is all automatically generated fromthe XML/TXT/CSV file or in absence of it the directory as it does now.

                        [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                        Admin Sandbox Login: sandbox Password: castle