Download-Header, die bei mir funktionieren:
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, re-check=0");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" .$row['file']);
header("Content-Transfer-Encoding: binary");
return readfile("pfad/zur/Datei/" .$row['file']);
Das Return kommt aus der Klasse - ohne ...
$this->pi_wrapInBaseClass($content);
Der Link, der den Download erzeugt, ist bei mit eine eID, welche alleinig den Download liefert und keine weiteren Header-Daten aus irgendwelchem Template-Rendering oder so.
ext_localconf.php:
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$_EXTKEY.'_download'] = 'EXT:'.$_EXTKEY.'/lib/download.php';
lib/download.php:
require_once(t3lib_extMgm::extPath('extension').'pi1/class.tx_extension_pi1.php');
if (t3lib_div::int_from_ver($GLOBALS['TYPO_VERSION']) < 4003000) {
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_tslib.'class.tslib_feuserauth.php');
require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
require_once(PATH_tslib.'class.tslib_content.php');
}
// ***********************************
// Creating a $TSFE object
// ***********************************
$TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$id = t3lib_div::_GET('id');
if (!isset($id)) $id = 0;
$id = htmlspecialchars($id);
$GLOBALS['TSFE'] = new $TSFEclassName($TYPO3_CONF_VARS, $id, '0', 1, '', '','','');
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->determineId();
// *******************************************
// Get compressed $TCA-Array();
// After this, we should now have a valid $TCA, though minimized
// *******************************************
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
// ******************************************************
// Get config if not already gotten
// After this, we should have a valid config-array ready
// ******************************************************
$GLOBALS['TSFE']->getConfigArray();
// *******************************************
// Setting language and locale
// *******************************************
$GLOBALS['TT']->push('Setting language and locale','');
$GLOBALS['TSFE']->settingLanguage();
$GLOBALS['TSFE']->settingLocale();
$GLOBALS['TT']->pull();
// *******************************************
// Invoke the freecap plugin
// *******************************************
$tx_extension_pi1 = t3lib_div::makeInstance('tx_extension_pi1');
$tx_extension_pi1->cObj = t3lib_div::makeInstance('tslib_cObj');
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$tx_extension_pi1->prefixId.'.'];
$conf['download'] = 1;
echo $tx_extension_pi1->main("", $conf);
?>
(1000 Dank an Stanislas Rolland an dieser Stelle, der diese Implementierung in der sr_freecap-Extension vormachte.)
class.extension.php->main():
if (intval($conf['download'])) {
return self::provideDownload();
}
class.extension.php->provideDownload(){
private function provideDownload(){
if ($this->piVars['downloadID']){
// DB-Daten holen
// ..
// Header-Kram von Oben
}
}
}
Dabei ist darauf zu achten, dass alle Dateien keine Leerzeichen oder ähnliches vor dem <?php oder nach dem ?> haben - die Dateien werden included. Wenn ein Zeichen vorhanden wäre, dann würde der Webserver die Header senden.
Reihenfolge:
index.php?eID=tx_extension_download&tx_extenion_pi1[downloadID]=0815 -> ext_localconf.php -> lib/download.php -> pi1/class.extension_pi1.php -> Methode: provideDownload() -> Return: Header mit der Datei.
Edit: Kann man irgendwie die Smilies abschalten? Das zerhaut den Quelltext.