public static function downloadFile($cid, $type = '') { global $jlistConfig; jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $app = JFactory::getApplication(); $db = JFactory::getDBO(); clearstatcache(); $view_types = array(); $view_types = explode(',', $jlistConfig['file.types.view']); // get path $db->SetQuery("SELECT * FROM #__jdownloads_files WHERE file_id = {$cid}"); $file = $db->loadObject(); if ($type == 'prev') { if ($file->preview_filename) { $file = $jlistConfig['files.uploaddir'] . DS . $jlistConfig['preview.files.folder.name'] . DS . $file->preview_filename; } } else { if ($file->url_download) { if ($file->cat_id > 1) { // 'uncategorised' download is NOT selected $db->SetQuery("SELECT cat_dir, cat_dir_parent FROM #__jdownloads_categories WHERE id = {$file->cat_id}"); $cat_dirs = $db->loadObject(); // build the complete stored category path if ($cat_dirs->cat_dir_parent != '') { $cat_dir = $cat_dirs->cat_dir_parent . DS . $cat_dirs->cat_dir; } else { $cat_dir = $cat_dirs->cat_dir; } $filename_direct = $jlistConfig['files.uploaddir'] . DS . $cat_dir . DS . $file->url_download; $file = $jlistConfig['files.uploaddir'] . DS . $cat_dir . DS . $file->url_download; } else { // 'uncategorised' download IS selected $file = $jlistConfig['files.uploaddir'] . DS . $jlistConfig['uncategorised.files.folder.name'] . DS . $file->url_download; } } } if (!jFile::exists($file)) { exit; } $len = filesize($file); // if set the option for direct link to the file if (!$jlistConfig['use.php.script.for.download']) { if (empty($filename_direct)) { $app->redirect($file); } else { $app->redirect($filename_direct); } } else { $filename = basename($file); $file_extension = jFile::getExt($filename); $ctype = self::datei_mime($file_extension); ob_end_clean(); // needed for MS IE - otherwise content disposition is not used? if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header("Cache-Control: public, must-revalidate"); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // header("Pragma: no-cache"); // Problems with MS IE header("Expires: 0"); header("Content-Description: File Transfer"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Type: " . $ctype); header("Content-Length: " . (string) $len); if (!in_array($file_extension, $view_types)) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } else { // view file in browser header('Content-Disposition: inline; filename="' . $filename . '"'); } header("Content-Transfer-Encoding: binary\n"); // set_time_limit doesn't work in safe mode if (!ini_get('safe_mode')) { @set_time_limit(0); } @readfile($file); } exit; }