We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    wink Indeed, taking a break to take a walk for half an hour or so every now and then benefits both brain and butt wink
      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
      • 27088
      • 11 Posts
      [from MozillaZine Knowledge Base]
      Filenames with spaces are truncated upon download

      When downloading certain files, you may find that the filename is truncated up to the first space. Thus, a link to download the file "My Report.doc" produces a save dialog containing "My" as the filename. This is a case of download.php incorrectly sending the content-disposition filename, cut (truncated) at space, and the browser coping as best it can.

      Fix
      Change the code in download.php at line 72 to this:
      header("Content-Disposition: attachment; filename=\"".basename($filename)."\"");


      Detailed Explanation
      Using the earlier example of "My Report.doc", the webserver should send these HTTP headers to adhere to the specification and be compatible with all browsers:
      Content-Type: application/msword
      Content-Disposition: attachment; filename="My Report.doc"
      Note that the filename is surrounded by double quotes, per RFC 2231. This allows for the use of extended characters within the filename (i.e., international characters, though at present Internet Explorer does not support this internationalization).

      Not including the enclosing quotes around the filename creates an ambiguity when parsing the header for the filename when the browser has to consider the possibility of internationalized filenames. As Internet Explorer does not have to worry about this, it will parse the filename until the end of the line. Mozilla will not.

      External Links
        • 7923
        • 4,213 Posts
        What a nicely detailed post! I’m just going to admire it for a minute grin

        Thanks alot for the fix!


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 15987
          • 786 Posts
          Thanks for the update, I will get it added to the version in the repository. I never thought of testing that
            • 23383
            • 138 Posts
            Hi again ! I’ve a problem with browse directories :s
            I can see too many things for me : if I type .. in URL (like this http://127.0.0.1/download.html?relPath=/../) I can browse all my directories.

            Anyone an idea ? I was looking at this code of the snippet
            if ($browseDirectories) {
                $relPath = urldecode($_GET['relPath']);
                // Just for safety, directory traversal should not be possible
                $relPath = strtr($relPath, '../', '');
                $dwnPath .= $relPath;
            }
            

            But don’t know why it allows directory traversal. :s

            Thanks for help.

            PS : I’m using either Windows XP, apache 2.2.2, php 5.1.4
            or FreeBSD 6.1, apache 1.3.34, php 4.4.2
              • 15987
              • 786 Posts
              Try this, it should eliminate the problem:

              if ($browseDirectories) {
                  $relPath = urldecode($_GET['relPath']);
                  // Just for safety, directory traversal should not be possible
                  $badPath = array('../','/../','/..');
                  $relPath = str_replace($badPath, "", $relPath);
                  $dwnPath .= $relPath;
              }
              
                • 23383
                • 138 Posts
                Thank you, It works fine !
                  • 23383
                  • 138 Posts
                  I’m back ! I was wondering if it was possible to use symlinks with the snippet...
                  In fact, I changed the code a little bit like this (around line 360 ?)
                  if ($file['type']!='dir' && $file['type']!='link')
                              {
                              	if ($downloadCount) 
                                  {
                                      $fullPath = base64_encode($getFolder.$relPath);
                                      $fileLink = $download . '?path=' . $fullPath . '&fileName=' . $file['name'];
                                  } else 
                                  {
                                      $fullPath = $getFolder.$relPath;
                                      $fileLink = $fullPath . '/' . $file['name'];                    
                                  }
                              } 
                              elseif ($file['type']=='link'){
                  		$addUrl = $modx->config['friendly_urls']? '?':'&';
                                  $fileLink = $currentPageLink . $addUrl . 'relPath=' . "/wheresymlinkpointsto" . '/' . urlencode($file['name']);
                                  $fileImage = '<img src="' . $imgLocat . '/' . $imgTypes['folder'] . '" alt="" />';
                                  $file['sizetext'] = '-';
                                  $file['name'] = '<em>' . $file['name'] . '</em>'; 
                              }
                  


                  But my problem is that i can’t go back to the previous folder with ".."

                  For example I’m browsing with filedownload /assets/files/1/dogs/ with inside a link called huskey which points to ../all/dogs/h/
                  When I’m clicking on huskey, I’m on /assets/files/all/dogs/h/. That’s ok. But now I’d like to be send on /assets/files/1/ when I’m clicking on ".." in the menu (and not /assets/files/all/dogs/)...
                  Has someone an idea ?

                  Thank you.
                    • 17412
                    • 270 Posts
                    I can’t seem to get this to work. I have followed the setup instructions to the dot and the call to the snippet doesn’t get parsed, it just displays in the page as:

                    [[FileDownload?getFolder=`assets/js` &tplList=`FileDownloads` &useHlt=`1` &evenClass=`evenrow` &oddClass=`oddrow`]]


                    Any ideas?

                    Thanks.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Check the spelling of the snippet name. Refresh the site cache after any changes.
                        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