File Size & Resume Option is Not Showing While Downloading File with HTTP Header

I’ve written a code in php, which is used in downloading link like https://example.com/dl.php&file=test.zip. Here the file dl.php checks the HTTP refer, if it is allowed then it download the file from “up” directory. it gets the file name from “file” URL parameter and check the file in “up” directory and download it.

Everything is working perfectly, but when the file is being downloaded it doesn’t show File size and Resume option. I am using WHM/cPanel with Engintron. Its fresh server installation. Same script works perfectly on AApanel but doesn’t show file size here on WHM. Any help would be highly appreciated.

here is my code for dl.php

<?php
// Allowed referring domains
$allowedDomains = [
    'https://reidostorrents.net.br/',
    'https://programastorrent.com.br/',
    'https://fullprogramindir.com.tr/',
    'https://jogosbaixar.net/',
    'https://gustavortech.org/',
    'https://ativadorfiles.com/',
    'https://downloadcomputerprograms.org/',
    'https://baixakiprogramas.com.br/',
    'https://computergamesegypt.com/'
];

// Get the referring domain from the HTTP Referer header
$referer = $_SERVER['HTTP_REFERER'];

// Check if the referring domain is in the allowed domains list
if (in_array($referer, $allowedDomains) || startsWith($referer, 'https://reidostorrents.net.br')) {
    // Allow access to the specified file in the directory
    $directory = __DIR__ . '/up'; // Ensure you are pointing to the correct directory

    // Get the requested file from the query parameter
    $requestedFile = isset($_GET['file']) ? $_GET['file'] : '';

    // Validate the requested file and check for allowed extensions
    $allowedExtensions = ['zip', 'rar'];
    $fileExtension = pathinfo($requestedFile, PATHINFO_EXTENSION);
    $file = $directory . '/' . basename($requestedFile);

    if (is_file($file) && in_array($fileExtension, $allowedExtensions)) {
        // If the file exists and has an allowed extension, handle resume download
        $fileSize = filesize($file);

        // Handle range requests
        $range = isset($_SERVER['HTTP_RANGE']) ? $_SERVER['HTTP_RANGE'] : '';
        if ($range) {
            list($unit, $range) = explode('=', $range, 2);
            if ($unit == 'bytes') {
                list($start, $end) = explode('-', $range, 2);
                $start = (int)$start;
                $end = (isset($end) && is_numeric($end)) ? (int)$end : $fileSize - 1;

                if ($start > $end || $start >= $fileSize || $end >= $fileSize) {
                    header('HTTP/1.1 416 Requested Range Not Satisfiable');
                    header("Content-Range: bytes */$fileSize");
                    exit;
                }
            } else {
                header('HTTP/1.1 416 Requested Range Not Satisfiable');
                exit;
            }
        } else {
            $start = 0;
            $end = $fileSize - 1;
        }

        $length = $end - $start + 1;

        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($file) . '"');
        header('Content-Length: ' . $length);
        header('Accept-Ranges: bytes');

        if ($range) {
            header('HTTP/1.1 206 Partial Content');
            header("Content-Range: bytes $start-$end/$fileSize");
        } else {
            header('HTTP/1.1 200 OK');
        }

        $fileHandle = fopen($file, 'rb');
        fseek($fileHandle, $start);

        $bufferSize = 8192;
        while (!feof($fileHandle) && ($pos = ftell($fileHandle)) <= $end) {
            if ($pos + $bufferSize > $end) {
                $bufferSize = $end - $pos + 1;
            }
            echo fread($fileHandle, $bufferSize);
            ob_flush();
            flush();
        }

        fclose($fileHandle);
    } else {
        // Invalid or non-existent file or extension
        http_response_code(404);
        echo 'No File Found.';
    }
} else {
    // Show forbidden error
    http_response_code(403);
    header('Location: https://reidostorrents.net.br');
    exit;
}

// Helper function to check if a string starts with another string
function startsWith($haystack, $needle) {
    return strpos($haystack, $needle) === 0;
}
?>

and here is .htaccess file content

# Enable the Rewrite Engine
RewriteEngine On

# Allow access to all files
<Files *>
    Order Allow,Deny
    Allow from all
</Files>

# Disable directory listing if desired
Options -Indexes

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật