We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29525
    • 388 Posts
    OK, guys, Thanks for hanging in here with me. I’m almost there.

    FileDownload Snippet is working just fine with Friendly URLs.

    I’ve installed the FileDownloadPlugin and I am getting 404 errors when I click on the file displayed on the page.

    Not sure how much information I should provide. Here’s what I think is relevant, but please tell me what else I can tell you if this isn’t enough.

    FileDownload (v2.6)
    File Download Plugin (v1.2) with OnWebPagePrerender checked
    Snippet call
    [!FileDownload? &getFolder=`assets/files` &tplList=`filedownloadtpl`!]


    Files are stored in:
    C:\wamp\www\assets\files\content-brief-example.pdf

    Template variable contains:
    	assets/files

    Friendly URL are enabled.
    Friendly alias path is set to NO

    Switching rewrite rule from:
    #RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    to
    RewriteRule ^([^/]*)/?(.*)$ index.php?q=$1&d=$2 [L,QSA]

    has no effect.

    HTML produced on page is
    <tr class="fd-file fd-alt">
    	<td><a href="/file-download.html/content-brief-example.pdf">content-brief-example.pdf</a> <span style="font-size:80%"></td>
    	</tr>


    I’m assuming this works exactly the same on wamp as it would on my server.

    Any ideas why I’m getting 404s?

    Thank you!
      www.terrybarthdesign.com
      • 19506
      • 10 Posts
      This is a great snippet and is working perfectly for what I need it for except for just 1 thing.

      Brief history: I’m creating a site where users will have sensitive information in pdf files added to a folder. After they log in, they can access a page called My Account that is using this snippet and will only show them files that are tagged as theirs.

      The way I figured to "tag" the files is to have them all begin with a unique number stored in the database. For example the LoginUserID (but i won’t be using this for the final production, just for proof-of-concept).

      I added this code in the FileDownload snippet before all the variable declarations.

      $getFile= $modx->getLoginUserID();


      So in my example, it will return all files with the file name "2" since that is the users ID number. I’d like for it to retrieve all files that begin with 2. If I were writing this in DOS it’d be "2*.*" and would retrieve 2-file1.pdf, 2-file2.pdf, 2-file3.pdf...

      I can’t figure out how to add wildcards at the end to retrieve more then just 1 file.
      Is there a way, how can i add wildcards to the &getFile variable?

      (I won’t be using userID since this would retrieve files for ID 2, 20, 21, ... 200, 201... etc. I’ll be using a 4 digit number)

        • 31471
        • 206 Posts
        I would make a folder for each user and put their files in it.
          • 19506
          • 10 Posts
          I went with vhollo’s suggestion of creating a folder for each user.
          After all my customizing and everything i did, I was able to show just the files within the folder for that user... BUT I can’t actually download the files!!

          So I backtracked, and set it up back to default and just added 1 users folder directly into the TemplateVariable (account/2) It shows me the files within that folder no matter who I log in as, but I can’t download the file.

          I’m not using friendly URLs so I don’t believe I need to do anything with the .htaccess and rewriterules.

          Any help would be great!!
          Thanks
            • 31471
            • 206 Posts
            From that you’re using the TV I suppose you’re using the plugin.
            The plugin can not serve the files without the .htaccess modification.
            So either disable the plugin or alter your .htaccess.
            (And then I suggest you to make the folders again wink
              • 19506
              • 10 Posts
              Yup I got it to work but it does expose the full URL to the public and that can’t happen with these files.

              I’ll tinker with the .htaccess file and see if I can get it to work.
              I thought I only needed the .htaccess file if I was using the riendly URLs

              Thanks for your help.
              If you have insight to the .htaccess file, i’m all ears!
                • 19506
                • 10 Posts
                Can someone help me out with this .htaccess file.
                I placed the .htaccess file in the directory where my download folders are:

                /account/

                under that folder I will have account folders that will actually hold the files they have access to:

                /account/300
                /account/301
                ...

                Here is what the .htaccess file has in it enabled

                Options +FollowSymlinks
                RewriteEngine On
                RewriteBase /account
                RewriteRule ^([^/]*)/?(.*)$ index.php?q=$1&d=$2 [L,QSA]
                


                I even tried putting it in each folder and just changing the RewriteBase to reflect the correct folder it’s in:
                Options +FollowSymlinks
                RewriteEngine On
                RewriteBase /account/300
                RewriteRule ^([^/]*)/?(.*)$ index.php?q=$1&d=$2 [L,QSA]
                


                Should anything else be added?
                I’ve never dealt with rewrite rules before sad

                Should I be placing the .htaccess file somewhere else?
                My folder structure off of root looks like this:
                /account/300/
                /account/301/
                /assets/...
                /manager/...
                  • 31471
                  • 206 Posts
                  Put it where the index.php is...
                    • 4749
                    • 623 Posts
                    @mikeysweet: I’m looking to do something similar. Could you let us know how it goes and report back any issues or successes? That would be a great help. Thanks.
                      The MODx has you...
                      Utah Web Design
                      • 19506
                      • 10 Posts
                      @vhollo, @cbaone - Well success is in sight but unfortunately it looks like the hosting service I am using doesn’t have mod_rewrite enabled.

                      Right now here is what I’ve done:

                      1 - Hacked the core code to add a new field called Acccount for all web users created.
                      2 - Used FileDownload to dynamically add the account number as the &getFolder (i.e. /account/300)
                      3 - The links work if I bypass the FileDownloadPlugin since my hosting service disabled mod_rewrite.

                      I’m seeing if my hosting service can get mod_rewrite enabled. I’m also now trying to see how I can get SSL into the picture and/or use .htaccess to only allow the logged in user to access their specific folder.

                      Anyone enabled SSL?
                      Does anyone know how to incorporate .htaccess/.htpasswd into the MODx system that would tag a specific folder with a specific web user??