We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    Yup, complete waste of time then.
      Mostly harmless.
      • 19309
      • 49 Posts
      Just tested FileDownloadPE and experienced the corrupt file problem, too. I only tested pdf files, since these are all I need right now. The original files can be downloaded from the server without problem.

      But as soon as the downloads are “tunneled” through a resource with the FileDownloadPE template, the resulting pdf files have only about half the original filesize and produces error messages when one tries to open it in the AcrobatReader.

      Are there any alternatives which make it possible to provide a file download throuh a resource in the document tree?

      I ask because I want to build a related downloads feature using FileDownloadPE, Related and Ditto. This should make it possible to choose one or more downloads for each individual page, which then appear in the sidebar or somewhere else on that particular page. But if the downloads won’t work, trying to make these three snippets play nicely together is obsolete.
        • 25483
        • 741 Posts
        I did strip most of the code and changed it to a example that they give on php.net:

        <?php
        //  Set default snippet parameters.
        $filename   = isset($filename)  ? $filename : null;
        
        // Defaults for Template Variables:
        $alias = $_REQUEST['q'];
        if (!$alias) $alias = Download::GetAlias($_REQUEST['id']);
        $fileMimeTV = isset($fileMimeTV) ? $fileMimeTV : 'FileMime';
        $filePathTV = isset($filePathTV) ? $filePathTV : 'File';
        
        // Download the requested file.
        $mime       = $modx->getTemplateVarOutput($fileMimeTV);
        $mime       = $mime[$fileMimeTV];
        $file       = $modx->getTemplateVarOutput($filePathTV);
        $file       = $modx->config['base_path'] . $file[$filePathTV];
        
        if (file_exists($file)) {
            header('Content-Description: File Transfer');
            header('Content-Type:'. $mime);
            header('Content-Disposition: attachment; filename='.basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            readfile($file);
            return;
        }
        ?>
        


        Even with this code it doesn’t work, I still get corrupted files.
          with regards,

          Ronald Lokers
          'Front-end developer' @ h2o Media

          • 12379
          • 460 Posts
          Nice try. Would be great to get this snippet up and running again if there’s anybody out there keen to get involved please.
            Mostly harmless.
            • 25483
            • 741 Posts
            Just to let you guys know: I changed "return" to "exit" and now my custom snippet is working, I think the same would work with the original FiledownloadPE!
              with regards,

              Ronald Lokers
              'Front-end developer' @ h2o Media

              • 13808
              • 61 Posts
              @MediaGuy < You rock my world. Thank you so much for getting to the bottom of that!
                • 29877
                • 35 Posts
                I decided to check in on this thread today and catch up with what’s new. I have been needing to revisit this issue on my website and find a solution asap.

                I’d like to report that so far, it seems I am not experiencing the issues that I expressed in earlier posts of mine. I tried out what Media Guy suggested in post #83 and #85 (being the most important). I made a duplicate of my FileDownloadPE snippet as to not disturb the original. I completely replaced the existing PHP code with what Media Guy listed in post #83. I then made the change on the third to last line, as he explained in post #85.

                I’ve been testing out my existing download link documents and the ones that have been showing problems before making the code change seem to be operating now as they should. I am no longer getting errors when downloading and opening PDF documents.

                Additionally, I’d like to mention that in the original installation instructions written by Scotty Delicious, he tells you to select "text/plain" for ’Internet Media Type’ under ’Settings’ when creating/editing your download document. I noticed that while using version Evolution 1.0.2 (I was previously using Evolution 0.9.6.3), if you select "application/pdf" instead of "text/plain", the tree will display an Acrobat-like icon for the document. If you offer different file formats for download, it would be nice to quickly see what format each document is. I was worried this would affect the operation. In testing, it hasn’t seem to change the operation any. Try it out for yourself.
                  • 18913
                  • 654 Posts
                  I am trying to get this snippet to work (Evo) and am running into problems. Specifically, using the example given on Scotty D’s site, I correctly get a link to the document I want to download (in this case test.zip). The document has this as both a title and alias, has nothing in the content area, has two TV’s set with the correct values and under settings bot "text/plain" and dispostion=attachment are set.

                  What I get downloaded instead of the file is a bit of next, specifically, the call to the snippet from the "Downloads" template. I.e. [ !FileDownloadPE! ]

                  I am assuming I’ve done something boneheaded. To try to rectify this myself I replaced the snippet code as per messages #83 and #85 but again, no luck.

                  Can anyone point out what I am likely doing wrong?

                  Also, does anyone know of any mods to the snippet to make the download link expire after a certain amount of time? If there are other solutions to all this (namely providing an ability to download a file, which I hope to tie into a Shopkeeper-like solution) I’d be grateful.

                  TIA,
                  MattC
                    • 18913
                    • 654 Posts
                    Okay, I got it figured out. There were two errant spaces in the snippet call used by the zip file’s template.

                    Onto expiring links. Looks like there’s something called dp4tc that’s been submitted ...
                    MattC
                    • Last Of The Romans Reply #90, 14 years ago
                      Hi Jonny,

                      i make this change:
                      Quote from: abyssalplain at Nov 11, 2008, 11:05 AM

                      Another issue I noticed is that the download counter only works properly if the download link page is placed in the root, and it won’t count properly downloads of the same file from different pages, and doesn’t work with friendly alias paths too well.

                      I fixed it, replace this part which starts on line 25:

                      // Get download count for requested document.
                      if ($action == 'count')
                      {
                      	$filename = isset($filename) ? $filename : Download::GetAlias($id);
                      	
                      	if ($modx->config['friendly_urls'] && $modx->config['friendly_alias_urls']) 
                      	{
                      		$_pIds = $modx->getParentIds($id);
                      
                      		foreach($_pIds as $pId) 
                      		{
                      			$_alias = Download::GetAlias($pId);
                      			$_aliaspath[] = (!$_alias) ? $pId : $_alias;
                      		}
                      		$filename = implode("/",$_aliaspath)."/".$filename;
                      	}
                      	
                          return Download::Count($filename, $_table, $dberror, $nofile);
                      }
                      


                      Not sure if this project / thread is dead, if not then I can fix all the issues and submit it as the next version.

                      cheers

                      Jonny


                      and i get:
                      « MODx Parse Error »
                      
                      MODx encountered the following error while attempting to parse the requested resource:
                      « PHP Parse Error »
                       
                      PHP error debug
                        Error:	implode() [function.implode]: Bad arguments.	 
                        Error type/ Nr.:	Warning - 2	 
                        File:	/var/www/vhosts/domain.net/httpdocs/manager/includes/document.parser.class.inc.php(773) : eval()'d code	 
                        Line:	38	 
                       
                      Parser timing
                        MySQL:	0.0889 s	(35 Requests)
                        PHP:	0.1053 s	 
                        Total:	0.1942 s	 


                      have you time to fix errors and make next release?
                        palma non sine pulvere