Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | <?php |
2 | |||
3 | if (!defined('WBLEGAL')) die('Kann nicht ohne Personal WebBase ausgeführt werden.'); |
||
4 | |||
5 | $res = db_query("SELECT `data`, `type`, `filename` FROM `".$WBConfig->getMySQLPrefix()."files` WHERE `id` = '".db_escape($id)."' AND `user_cnid` = '".$benutzer['id']."'"); |
||
6 | |||
7 | if (db_num($res) == 0) |
||
8 | die($header.'<b>Fehler</b><br><br>Der Download wurde nicht gefunden.'.$footer); |
||
9 | |||
10 | $row = db_fetch($res); |
||
11 | |||
12 | // Abgeänderte Version von http://www.php.net/manual/de/function.fread.php (Benutzerkommentar) |
||
13 | |||
14 | $size = strlen($row['data']); |
||
15 | $filename = $row['filename']; |
||
16 | $ctype = $row['type']; //application/force-download |
||
17 | |||
18 | if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) |
||
19 | $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); |
||
20 | |||
21 | //if (!headers_sent()) header("Cache-Control:"); |
||
22 | //if (!headers_sent()) header("Cache-Control: public"); |
||
23 | if (!headers_sent()) header("Content-Type: $ctype"); |
||
24 | if (!headers_sent()) header('Content-Disposition: attachment; filename="'.$filename.'"'); |
||
25 | if (!headers_sent()) header("Accept-Ranges: bytes"); |
||
26 | |||
27 | if (isset($_SERVER['HTTP_RANGE'])) |
||
28 | { |
||
29 | $ary = explode("=",$_SERVER['HTTP_RANGE']); |
||
30 | if (count($ary) != 2) die(''); // Hinzugefügt |
||
31 | list($a, $range) = $ary; |
||
32 | str_replace($range, "-", $range); |
||
33 | $size2=$size-1; |
||
34 | $new_length=$size2-$range; |
||
35 | if (!headers_sent()) header("HTTP/1.1 206 Partial Content"); |
||
36 | if (!headers_sent()) header("Content-Length: $new_length"); |
||
37 | if (!headers_sent()) header("Content-Range: bytes $range$size2/$size"); |
||
38 | } |
||
39 | else |
||
40 | { |
||
41 | $size2=$size-1; |
||
42 | if (!headers_sent()) header("Content-Range: bytes 0-$size2/$size"); |
||
43 | if (!headers_sent()) header("Content-Length: ".$size); |
||
44 | } |
||
45 | |||
46 | flush(); |
||
47 | |||
48 | $buffer = 1024*8; |
||
49 | $range = 0; |
||
50 | while ($range <= $size) |
||
51 | { |
||
52 | print(substr($row['data'], $range, $buffer)); // binary |
||
53 | $range += $buffer; |
||
54 | flush(); |
||
55 | } |
||
56 | |||
57 | die(); |
||
58 | |||
59 | // Das "die" verhindert im Debugmodus die Fehlermeldung |
||
60 | // Notice: Trying to get property of non-object in /usr/share/php/Services/W3C/HTMLValidator.php on line 316 |
||
61 | |||
62 | // Info: http://wordpress.macosbrain.com/2006/04/30/php-download-funktion-mit-multipart-und-resume/ |
||
63 | |||
64 | ?> |