From 92e35de9f1c517ed407abd5e53537dc614dd8827 Mon Sep 17 00:00:00 2001 From: Robert Tidey Date: Tue, 15 Sep 2015 13:24:04 +0100 Subject: [PATCH] Filesize handling for files greater than 2GB --- README.md | 2 +- www/config.php | 26 +++++++++++++++++++++----- www/download.php | 8 -------- www/preview.php | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) delete mode 100644 www/download.php diff --git a/README.md b/README.md index b52f2ae2..ab0d5baa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ Web based interface for controlling the Raspberry Pi Camera, includes motion detection, time lapse, and image and video recording. -Current version 6.0.7 +Current version 6.0.8 All information on this project can be found here: http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276 The wiki page can be found here: diff --git a/www/config.php b/www/config.php index a269790f..2ef4dd7d 100755 --- a/www/config.php +++ b/www/config.php @@ -3,7 +3,7 @@ define('LBASE_DIR',dirname(__FILE__)); //Global defines and utility functions // version string - define('APP_VERSION', 'v6.0.7'); + define('APP_VERSION', 'v6.0.8'); // name of this application define('APP_NAME', 'RPi Cam Control'); @@ -41,6 +41,9 @@ // file where schedule log is stored define('LOGFILE_SCHEDULE', 'scheduleLog.txt'); + // control how filesize is extracted, 0 is fast and works for files up to 4GB, 1 is slower + define('FILESIZE_METHOD', '0'); + // debug log function function writeDebugLog($msg) { $log = fopen(LBASE_DIR . '/' . LOGFILE_DEBUG, 'a'); @@ -145,6 +148,19 @@ function findLapseFiles($d) { return $lapsefiles; } + //function to get filesize (native php has 2GB limit) + function filesize_n($path) { + if (FILESIZE_METHOD == '0') { + $size = filesize($path); + if ($size > 0) + return $size; + else + return 4294967296 - $size; + } else { + return trim(`stat -c%s $path`); + } + } + //function to delete all files associated with a thumb name //returns space freed in kB //if $del = false just calculate space which would be freed @@ -155,21 +171,21 @@ function deleteFile($d, $del = true) { // For time lapse try to delete all from this batch $files = findLapseFiles($d); foreach($files as $file) { - $size += filesize($file); + $size += filesize_n($file); if ($del) if(!unlink($file)) $debugString .= "F "; } } else { $tFile = dataFilename($d); if (file_exists(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile")) { - $size += filesize(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile"); + $size += filesize_n(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile"); if ($del) unlink(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile"); } if ($t == 'v' && file_exists(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile.dat")) { - $size += filesize(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile.dat"); + $size += filesize_n(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile.dat"); if ($del) unlink(LBASE_DIR . '/' . MEDIA_PATH . "/$tFile.dat"); } } - $size += filesize(LBASE_DIR . '/' . MEDIA_PATH . "/$d"); + $size += filesize_n(LBASE_DIR . '/' . MEDIA_PATH . "/$d"); if ($del) unlink(LBASE_DIR . '/' . MEDIA_PATH . "/$d"); return $size / 1024; } diff --git a/www/download.php b/www/download.php deleted file mode 100644 index 3b0b9c50..00000000 --- a/www/download.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/www/preview.php b/www/preview.php index 33e0604a..944c165f 100644 --- a/www/preview.php +++ b/www/preview.php @@ -233,7 +233,7 @@ function drawFile($f, $ts, $sel) { } $duration =''; if (file_exists(MEDIA_PATH . "/$rFile")) { - $fsz = round ((filesize(MEDIA_PATH . "/$rFile")) / 1024); + $fsz = round ((filesize_n(MEDIA_PATH . "/$rFile")) / 1024); $fModTime = filemtime(MEDIA_PATH . "/$rFile"); if ($fType == 'v') { $duration = ($fModTime - filemtime(MEDIA_PATH . "/$f")) . 's';