Skip to content

Instantly share code, notes, and snippets.

@SniperSister
Last active February 10, 2022 10:04
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SniperSister/3cbc2055282c08ed43d4682e4fd36498 to your computer and use it in GitHub Desktop.
Save SniperSister/3cbc2055282c08ed43d4682e4fd36498 to your computer and use it in GitHub Desktop.
<?php
/**
* @version 1.0.0
* @package Readmedia
* @copyright Copyright (C) 2018 David Jardin - djumla GmbH
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.djumla.de
*/
/* Initialize Joomla framework */
define('_JEXEC', 1);
// Load system defines
if (file_exists(dirname(__FILE__) . '/defines.php'))
{
require_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
/* Create the Application */
$mainframe = JFactory::getApplication('site');
/**************************************************/
// Your code starts here...
/**************************************************/
if (!JFactory::getUser()->id)
{
header("HTTP/1.0 403 access denied");
echo "Access denied";
exit();
}
$requestedFile = str_replace(JUri::root(), "", JUri::current());
$location = dirname(__FILE__) . "/" . $requestedFile;
if (!file_exists($location))
{
header("HTTP/1.0 404 file not found");
echo "File not found";
exit();
}
$size = filesize($location);
$time = date('r', filemtime($location));
$fm = @fopen($location, 'rb');
if (!$fm)
{
header("HTTP/1.0 505 Internal server error");
exit();
}
$begin = 0;
$end = $size;
header('HTTP/1.0 200 OK');
header("Content-Type: " . mime_content_type($location));
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header("Content-Disposition: inline; filename=" . basename($location));
header("Content-Transfer-Encoding: binary\n");
header("Last-Modified: $time");
header('Connection: close');
$cur = $begin;
fseek($fm, $begin, 0);
while (!feof($fm) && $cur < $end && (connection_status() == 0))
{
print fread($fm, min(1024 * 16, $end - $cur));
$cur += 1024 * 16;
}
@MarLinDT
Copy link

Vielen Dank für die Lösung!

Klappt super und dann noch in der htaccess bei der Übergabe für den Verzeichnisschutz Parameter für die Gruppen dran hängen und schon kann man bestimmte Bereiche für bestimmte Gruppen freigeben. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment