function download() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $authorised = $user->authorise('djcatalog2.filedownload', 'com_djcatalog2'); if ($authorised !== true) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } if ($out = DJCatalog2FileHelper::getFile($app->input->get('fid', '', 'int'))) { $app->input->set('format', 'raw'); echo $out; } else { JError::raiseError(404); return false; } }
function download() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $db = JFactory::getDbo(); $file_id = $app->input->getInt('fid', 0); $query = 'select i.created_by ' . 'from #__djc2_items as i, ' . '#__djc2_files as f where f.item_id = i.id and f.id=' . (int) $file_id; $db->setQuery($query); $owner = $db->loadResult(); $authorised = $user->authorise('djcatalog2.filedownload', 'com_djcatalog2') || $owner == $user->id ? true : false; if ($authorised !== true) { if ($user->guest) { $return = base64_encode(JRoute::_('index.php?option=com_djcatalog2&format=raw&task=download&fid=' . $file_id, false)); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $return, false), JText::_('COM_DJCATALOG2_LOGIN_FIRST')); return true; } else { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); return false; } } if (!DJCatalog2FileHelper::getFile($file_id)) { throw new Exception('', 404); return false; } // Close the application instead of returning from it. $app->close(); //return true; }