DIR : /home/kozerus/public_html/go/eidogo/tourney/download3.php

/home/kozerus/public_html/go/eidogo/tourney

<?php

    function download_file(string $file_path, string $file_name) {
        $file_size = filesize($file_path);
        $mime_type = mime_content_type($file_path);

        if(!isset($_SERVER['HTTP_RANGE'])) {
            // no range, serve the whole file

            header('Accept-Ranges: bytes');
            header('Content-Type: ' . $mime_type);
            header('Content-Length: ' . $file_size);
            header('Content-Disposition: attachment; filename="' . $file_name . '"');
            $file = fopen($file_path, 'rb');
            while (!feof($file)) {
                echo fread($file, 8192);
                flush();
            }
            fclose($file);
            return;
        }

        // range request, serve only the requested range

        list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2);
        $range = explode(',', $range_orig, 2)[0];
        list($range_start, $range_end) = explode('-', $range, 2);
        $range_start = intval($range_start);
        $range_end = intval($range_end);

        // check if range is valid

        if($size_unit != "bytes" || $range_start >= $range_end || $range_end > $file_size - 1 || $range_start < 0 || $range_end < 0) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header('Content-Range: bytes */' . $file_size);
            return;
        }

        // serve requested range

        header('HTTP/1.1 206 Partial Content');
        header('Accept-Ranges: bytes');
        header('Content-Type: ' . $mime_type);
        header('Content-Length: ' . ($range_end - $range_start + 1));
        header('Content-Disposition: attachment; filename="' . $file_name . '"');
        header('Content-Range: bytes ' . $range_start . '-' . $range_end . '/' . $file_size);
        $file = fopen($file_path, 'rb');
        fseek($file, $range_start);
        while (!feof($file) && $range_start < $range_end) {
            echo fread($file, 8192);
            flush();
            $range_start += 8192;
        }
        fclose($file);
    }

#    download_file("archive.zip", "download.zip");
download_file("/Volumes/ka1tbr2/ht/eidogo/tourney/sgf/print1.sgf", "print1.sgf");
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer