Skip to content

Instantly share code, notes, and snippets.

@SniperSister
Last active February 10, 2022 10:04
Show Gist options
  • 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;
}
@SniperSister
Copy link
Author

@tschombes das kann über das download Attribut in der Verlinkung erzwungen werden:
https://developer.mozilla.org/de/docs/Web/HTML/Element/a#attr-download

@tschombes
Copy link

@SniperSister kann man das nicht auch über das Script regeln? Sonst müsste ich ja jeden einzelnen Downloadlink anpassen.
Wie gesagt, ohne das Script dazwischen funktioniert es.

@SniperSister
Copy link
Author

Dann mal probieren ob es hilft aus dem Content-Disposition: inline ein Content-Disposition: attachment zu machen @tschombes

@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