Quote from: MediaGuy at Jan 11, 2010, 10:20 AM
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!
yes it does. You saved me a lot of heart ache thanks
Copy paste of original code with that simple exit change on download section
<?php
/**
* @package FileDownloadPE (Pirate Edition)
* @copyright 2008 MODx CMS/F Community.
* @license GPL v3 <http://www.gnu.org/licenses/gpl.html>
* @link http://scottydelicious.com/blog/2008/06/15/filedownloadpe
* @version 1.1 <2008.18.06 : June 18th 2006>
* @since 1.0 <2008.15.06 : June 15th 2006>
* @category PHP 5 Only. Requires PHP5 <http://gophp5.org/>
* @author Dr. Scotty Delicious, DFPA <[email protected]>
*/
// Set default snippet parameters.
$_table = 'downloads';
$filename = isset($filename) ? $filename : null;
$dberror = isset($dberror) ? $dberror : 'There was an error processing your download request.';
$nofile = isset($nofile) ? $nofile : 'No file specified.';
// Defaults for Template Variables:
$alias = $_REQUEST['q'];
if (!$alias) $alias = Download::GetAlias($_REQUEST['id']);
$fileMimeTV = isset($fileMimeTV) ? $fileMimeTV : 'FileMime';
$filePathTV = isset($filePathTV) ? $filePathTV : 'File';
// Get download count for requested document.
if ($action == 'count')
{
$filename = isset($filename) ? $filename : Download::GetAlias($id);
return Download::Count($filename, $_table, $dberror, $nofile);
}
// Download the requested file.
$mime = $modx->getTemplateVarOutput($fileMimeTV);
$mime = $mime[$fileMimeTV];
$file = $modx->getTemplateVarOutput($filePathTV);
$file = $modx->config['base_path'] . $file[$filePathTV];
return Download::File($alias, $file, $mime, $_table, $dberror, $nofile);
class Download
{
private static $error = '';
private static $nofile = '';
private static $table = '';
private static $filename = '';
public static function File($filename, $path, $mime, $table, $dberror, $nofile)
{
global $modx;
self::$table = $modx->getFullTableName($table);
self::$filename = $filename;
self::$error = $dberror;
self::$nofile = $nofile;
$check = self::_tableCheck($table);
if (!$check) return self::$error;
$info = self::_getInfo();
if (!$info) return self::$error;
if(is_file($path))
{
$count = ($info['count'] + 1);
$update = $modx->db->update("`count`=$count", self::$table, "`name`='$filename'");
// required for IE
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($path));
readfile($path);
exit;
}
else
{
return self::$error;
}
}
public static function Count($filename, $table, $dberror, $nofile)
{
if (!$filename) return $nofile;
global $modx;
self::$table = $modx->getFullTableName($table);
self::$filename = $filename;
self::$error = $dberror;
self::$nofile = $nofile;
$check = self::_tableCheck($table);
if (!$check) return self::$error;
$info = self::_getInfo();
if (!$info) return self::$error;
else return $info['count'];
}
public static function GetAlias($id = 0)
{
global $modx;
if (!$id) return false;
$site_content = $modx->getFullTableName('site_content');
$document = $modx->db->select('alias', $site_content, "`id` = $id");
$alias = $modx->db->getRow($document);
return $alias['alias'];
}
private static function _getInfo()
{
global $modx;
$search = $modx->db->select('*', self::$table, "`name` = '" .self::$filename. "'");
if ( $modx->db->getRecordCount($search) == 0 )
{
$insert = array('name' => self::$filename, 'count' => 0);
if (!$modx->db->insert($insert, self::$table)) return false;
$search = $modx->db->select('*', self::$table, "`name` = '" .self::$filename. "'");
}
$info = $modx->db->getRow($search);
return $info;
}
private static function _tableCheck($tablename)
{
global $modx;
$prefix = $modx->db->config['table_prefix'];
$check = "SHOW TABLES LIKE '" . $prefix . $tablename . "'";
$result = $modx->db->query($check);
$recordCount = $modx->db->getRecordCount($result);
if ($modx->db->getRecordCount($result) == 0)
{
$sql = "CREATE TABLE `" . $prefix . "downloads` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(128) NOT NULL default '',
`count` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
)";
if ( !$modx->db->query($sql) ) return false;
else $recordCount = 1;
}
return $recordCount;
}
}
?>
This works!