So, ich hab jetzt vieles ausprobiert, aber das Script bekomm ich nicht zum laufen. Ich schreib den Code mal hier rein, evtl. könnt ihr mir ja sagen, was ich falsch gemacht hab, ich kenn mich wirklich kein Stück aus...
index.html
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org//TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test von Download-Script</title>
<?
include('download_file.php');
</head>
<body>
<div><b>
<?php
print "Test";
?>
</b></div>
</body>
</html>
download_file.php
<?
#############################################################################
## ##
## Name: PHP-Download-Script ##
## Version: 1.2 ##
## Autor: Dennis Böge ##
## Co-Autor: Matthias Henckell ##
## Web:
www.boegesoft.de ,
www.mathesoft.de ##
## email:
download_file@boegesoft.de ##
## Lizenz: Freeware ##
## Haftung: Weder Dennis Böge noch mathesoft haften für folgenden ##
## Quelltext ##
## Benutzung auf eigene Gefahr. ##
## ##
## Beschreibung: Das PHP-Download-Script kann Dateien auch aus nicht ##
## über www erreichbaren Ordnern zum Download anbieten. ##
## Das sichert die eigenen Dateien vor dem "klau" über ##
## Direktverlinkung. Des Weiteren lässt sich somit auf ##
## einfachste Weise aus einem PHP-Script eine Datei zum ##
## Download anbieten. ##
## ##
## Antleitung: -(1)- Laden sie das Script auf auf ihre Seite ##
## -(2)- Optional schützen sie das File per .htaccess ##
## -(3)- Binden sie das Script mit ##
## include('download_file.php'); ##
## in ihre PHP-Seite ein ##
## -(4)- Senden sie das File an den Browser mit ##
## send_file_to_browser('path','filename'); ##
## -(5)- Achten sie darauf, daß KEIN TEXT vorher an den ##
## Browser gesendet wurde! ##
## - (6) Erweitern sie evtl. die Mime-Typen um eigene Typen ##
## ##
## ##
## History: ##
## ##
## - 18.06.04 - Version 1.2 - Änderungen von Bögesoft ##
## Ausbau nicht genutzer Routinen ##
## Pfad wird komplettiert ##
## ##
## - 24-05-03 - Version 1.1 - Änderungen von MATHEsoft ##
## MIME-Typ werden anhand von $real_filename erkannt (Dateierweiterung), ##
## wenn nicht, wird application/octetstream verwendet (klappt meistens); ##
## Filesize wird jetzt in jedem Fall ermittelt ##
## ##
## - 15-05-03 - Version 1.0 - Basisversion von Bögesoft ##
## Fehler: Der MIME-Type wird noch nicht automatisch erkant. Wer eine ##
## mögichkeit dafür kennt bitte an
mime-type@boegesoft.de mailen. ##
## Danke. ##
#############################################################################
function send_file_to_browser($filepath, $real_filename)
{
global $_SERVER, $HTTP_USER_AGENT, $HTTP_SERVER_VARS;
$filename = dirname(__FILE__).$filepath.$real_filename;
// Manuelle Mime-Type-Deklaration
$tmp = explode(".", $real_filename);
if ($tmp[1] == 'exe') $mimetype = "../files/schnappi/tarkan/tarkan.mp3";
else if ($tmp[1] == 'zip') $mimetype = "application/zip";
else if ($tmp[1] == 'txt') $mimetype = "text/plain";
else if ($tmp[1] == 'gz') $mimetype = "application/gzip";
else if ($tmp[1] == 'xls') $mimetype = "application/msexcel";
else if ($tmp[1] == 'doc') $mimetype = "application/msword";
else if ($tmp[1] == 'gif') $mimetype = "image/gif";
else if ($tmp[1] == 'jpeg') $mimetype = "image/jpeg";
else if ($tmp[1] == 'jpg') $mimetype = "image/jpeg";
else if ($tmp[1] == 'pdf') $mimetype = "application/pdf";
else if ($tmp[1] == 'pdf') $mimetype = "application/pdf";
else if ($tmp[1] == 'pdf') $mimetype = "application/pdf";
else $mimetype = "application/octetstream";
// Browsererkennung
if (!empty($_SERVER['HTTP_USER_AGENT'])) $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
else if (!isset($HTTP_USER_AGENT)) $HTTP_USER_AGENT = '';
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) $browser_agent = 'opera';
else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) $browser_agent = 'ie';
else $browser_agent = 'other';
// Mime-Type-Anpassung (Für IE und Opera)
if ( ($mimetype == 'application/octet-stream') || ($mimetype == 'application/octetstream')|| ($mimetype == 'image') )
{
if ( ($browser_agent == 'ie') || ($browser_agent == 'opera') ) $mimetype = 'application/octetstream';
else $mimetype = 'application/octet-stream';
}
// Compression AUS
@ob_end_clean();
@ini_set('zlib.output_compression', 'Off');
// Header senden
header('Pragma: public');
header('Content-Transfer-Encoding: none');
header('Content-Type: ' . $mimetype . '; name="' . $real_filename . '"');
if ($browser_agent == 'ie') header('Content-Disposition: inline; filename="' . $real_filename . '"');
else header('Content-Disposition: attachment; filename=' . $real_filename);
$size = @filesize($filename);
if ($size > 0) header('Content-length: '.$size);else header('Content-length: '.@strlen(@file_get_contents($filename)));
readfile($filename);
exit;
}
?>