<?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; } ?>
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
« 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