From f9e7e5f9c2bb0bca16b279527b8e07a360aa05cb Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 9 Jul 2014 02:40:23 +0200 Subject: [PATCH] Add filesize fallback for large files and 32bit PHP. --- src/_h5ai/client/js/inc/core/format.js | 4 ++-- src/_h5ai/server/php/inc/class-item.php | 28 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/_h5ai/client/js/inc/core/format.js b/src/_h5ai/client/js/inc/core/format.js index 9d6cc225..7991328f 100644 --- a/src/_h5ai/client/js/inc/core/format.js +++ b/src/_h5ai/client/js/inc/core/format.js @@ -4,12 +4,12 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) { var decimalMetric = { t: 1000.0, k: 1000.0, - u: ['B', 'KB', 'MB', 'GB', 'TB'] + u: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] }, binaryMetric = { t: 1024.0, k: 1024.0, - u: ['B', 'KiB', 'MiB', 'GiB', 'TiB'] + u: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] }, defaultMetric = decimalMetric, defaultDateFormat = 'YYYY-MM-DD HH:mm', diff --git a/src/_h5ai/server/php/inc/class-item.php b/src/_h5ai/server/php/inc/class-item.php index 33643b57..106fa047 100644 --- a/src/_h5ai/server/php/inc/class-item.php +++ b/src/_h5ai/server/php/inc/class-item.php @@ -28,7 +28,33 @@ class Item { if (is_file($path)) { - $size = @filesize($path); + if (PHP_INT_SIZE < 8) { + $_handle = fopen($path, "r"); + + $_pos = 0; + $_size = 1073741824; + fseek($_handle, 0, SEEK_SET); + while ($_size > 1) { + fseek($_handle, $_size, SEEK_CUR); + + if (fgetc($_handle) === false) { + fseek($_handle, -$_size, SEEK_CUR); + $_size = (int)($_size / 2); + } else { + fseek($_handle, -1, SEEK_CUR); + $_pos += $_size; + } + } + + while (fgetc($_handle) !== false) { + $_pos++; + } + fclose($_handle); + + $size = $_pos * 1e20; + } else { + $size = @filesize($path); + } } else if (is_dir($path)) {