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

    Good timing! I was just getting back to this today. I didn’t have the htaccess file quite right. Seems to be working now. Thank you for reminding me of what was already said. wink

    Now, I’m down to one last item (I hope). I really want this folder of files to be a collection of files to be downloaded. Some of them simply open in the browser. I understand the browser handles this according to the mime, but I really want all these files to always open a dialogue box to download. I’ve googled around and found a few php scripts for this purpose, but haven’t figured out how to integrate them into this.

    Ultimately, I want to create a page for a visitor to upload their files to a folder and for the owner to provide files for them to download. So we don’t want any of these files to open in the browser.

    Any recommendations would be really appreciated.

    Thanks.
      www.terrybarthdesign.com
      • 29525
      • 388 Posts
      Anybody?
        www.terrybarthdesign.com
        • 31471
        • 206 Posts
        Right click? cool
          • 29525
          • 388 Posts
          :) yes, yes, that’s always an option. Thank you. smiley

          I’d like this to be a nice and tidy for those clients who might not know of such advanced techniques.
            www.terrybarthdesign.com
            • 3749
            • 24,544 Posts
            There’s really no reliable way to force the download of a file.

            The best you could do, I think, would be to put this at the very top of each file (with no space above it):

            <?php
            header("Content-type: application/octet-stream");
            header("Content-Disposition: attachment; filename=filename_of_your_choice");
            ?>


            I think this would still generate a disturbing warning message in some browsers, depending on the security setting; and it should, if you think about it. For all the browser knows, It could be an executable trojan.

            Also, users can customize a browser so that it does anything they want with files of various mime types so there’s really no way to "force" anything.
              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
              • 29525
              • 388 Posts
              Bobray

              Yes, you’re right. I wouldn’t even try to force a download but just to prompt them to save vs open the file in their browser.

              So what do you mean by put this at the top of the file? Sorry if this is dumb question. . .
                www.terrybarthdesign.com
                • 3749
                • 24,544 Posts
                Quote from: Terry at Feb 02, 2009, 02:59 PM

                Bobray

                Yes, you’re right. I wouldn’t even try to force a download but just to prompt them to save vs open the file in their browser.

                So what do you mean by put this at the top of the file? Sorry if this is dumb question. . .

                I mean load the file in an editor and literally paste that code at the very top of the file, then save it. You could also insert it there on upload using a plugin or altering the upload code. The code won’t be in the downloaded file. Mind you, I’ve never tried it, I’m just reporting on what I’ve read.

                What I meant to say before is the not only can’t you force a download, you can’t count on forcing a download dialog box. Supposedly, the code above will do it almost every time in IE and FF, though, as long as the user hasn’t customized the browser actions, which few people would do.

                  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
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  Quote from: OpenGeek at Jan 26, 2009, 01:59 PM

                  bluespark, Terry, et al.:

                  Please see older posts in this topic -- http://modxcms.com/forums/index.php/topic,9276.msg73523.html#msg73523 regarding the friendly url issues.

                  I’ve tried your method, it didn’t work on my side.
                  I tried different way, by adding this in the .htaccess file, and WITHOUT make any change to the "filedownload.class.inc.php" file
                  # Exclude /assets and /manager directories from rewrite rules
                  RewriteRule ^(manager|assets) - [L]
                  

                  (I took it from the Evo’s ht.access)

                  And this one too, as mentioned in the earlier reply:
                  # For Friendly URLs
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteRule ^([^/]*)/?(.*)$ index.php?q=$1&d=$2 [L,QSA]
                  


                  The hyperlink now keeps the trailing "/", but the download works.
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 24731 ☆ A M B ☆
                    • 211 Posts
                    I’m wondering if this allows you to access files deeper in a folder tree structure.

                    So for example my download folder is /downloads/

                    but inside this folder I have other folders, something like:

                    /downloads/cat1/
                    /downloads/cat2/
                    /downloads/cat3/subcat1/

                    etc.

                    Would I be able to access a file inside a cat or a sub cat from the configured folder?

                    so using something like

                    http://www.mymodxsite.com/index?q=downloads&d=/downloads/cat1/myzipfile.zip
                    http://www.mymodxsite.com/index?q=downloads&d=/downloads/cat3/subcat1/myzipfile.zip

                    Would it do that?

                    tx.

                      • 2912
                      • 315 Posts
                      I’m so glad I stumble on this topic. It’s cured an age old problem with alias paths and file downloads I wouldn’t know where to start searching for.

                      Nice one all. smiley
                        BBloke