The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End cannot set header('Content-Length') greater than 2GB

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #202499

    i am using the following code to download files from the server:



    function my_filesize($fp) {
    $return = false;
    if (is_resource($fp)) {
    if (PHP_INT_SIZE < 8) {
    // 32bit
    if (0 === fseek($fp, 0, SEEK_END)) {
    $return = 0.0;
    $step = 0x7FFFFFFF;
    while ($step > 0) {
    if (0 === fseek($fp, – $step, SEEK_CUR)) {
    $return += floatval($step);
    } else {
    $step >>= 1;
    } elseif (0 === fseek($fp, 0, SEEK_END)) {
    // 64bit
    $return = ftell($fp);
    return $return;

    $url = $_GET[‘path’];
    $currentLocation = ‘http://&#8217;.$_SERVER[‘HTTP_HOST’];
    $fileURL = ‘../../’.str_replace($currentLocation,”,$url);

    $fileSize = my_filesize(fopen($fileURL,’r’));

    //echo $fileSize;

    if (file_exists($fileURL)) {
    header(‘Content-Description: File Transfer’);
    header(‘Content-Type: application/octet-stream’);
    header(‘Content-Disposition: attachment; filename=’.basename($fileURL));
    header(‘Content-Transfer-Encoding: binary’);
    header(‘Expires: 0’);
    header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
    header(‘Pragma: public’);
    header(‘Content-Length: ‘.$fileSize);


    but the problem is that the line “header(‘Content-Length’)” does not return file sizes greater than 2GB even when the actual file size is 50GB, i am using php-5.5.9 and apache2 on Ubuntu 14.04.2 LTS. So, i was wondering if there’s a way to solve this problem. Thanks!


    you can try the following function instead of my_filesize():

    function remote_filesize($url) {
        static $regex = '/^Content-Length: *+Kd++$/im';
        if (!$fp = @fopen($url, 'rb')) {
            return false;
        if (
            isset($http_response_header) &&
            preg_match($regex, implode("n", $http_response_header), $matches)
        ) {
            return (int)$matches[0];
        return strlen(stream_get_contents($fp));



    The problem isn’t that i can’t get the file size… i can get the file size just right but i can’t send the file size to the user via header(‘content-length’)… direct download, however, on the other hand, without the php, works just fine…. if i remove header(‘Content-Length’) the user can download the entire file but cannot see the total size and if i leave it untouched the client can only download 2GB of the entire file… so, i tried installing 64bit OS, 64bit apache and 64bit php on my 32bit machine and everything works but then i cannot upload files greater than 2GB via blueimp Jquery File Uploader even when i change everything in apache.conf and both the php.ini files, /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini…. but when i try to upload anything greater than 2GB without blueimp, with just a simple file uploader, it works like a charm…. i can’t seem to figure out what’s happening with me….

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.