3 $fileName = $_GET["name"];
6 $fileSize = filesize($fileName);
9 $contentRange = $_SERVER["HTTP_RANGE"];
10 if (isset($contentRange) && empty($_GET["norange"])) {
11 $range = explode("-", substr($contentRange, strlen("bytes=")));
12 $start = intval($range[0]);
13 if (!empty($range[1]))
14 $end = intval($range[1]);
15 $httpStatus = "206 Partial Content";
17 $httpStatus = "200 OK";
19 header("Status: " . $httpStatus);
20 header("HTTP/1.1 " . $httpStatus);
21 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
22 header("Pragma: no-cache");
23 header("Etag: " . '"' . $fileSize . "-" . filemtime($fileName) . '"');
24 header("Content-Type: " . $type);
25 header("Content-Length: " . ($end - $start) +
1);
26 if ($contentRange && empty($_GET["norange"])) {
27 header("Accept-Ranges: bytes");
28 header("Content-Range: bytes " . $start . "-" . $end . "/" . $fileSize);
30 header("Connection: close");
32 $chunkSize = 1024 * 256;
35 $fn = fopen($fileName, "rb");
36 fseek($fn, $offset, 0);
38 while (!feof($fn) && $offset <= $end && connection_status() == 0) {
39 $readSize = min($chunkSize, ($end - $offset) +
1);
40 $buffer = fread($fn, $readSize);
43 $offset +
= $chunkSize;