Skip to content

Commit

Permalink
Filesize handling for files greater than 2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Tidey committed Sep 15, 2015
1 parent 05bc51a commit 92e35de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
26 changes: 21 additions & 5 deletions www/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
8 changes: 0 additions & 8 deletions www/download.php

This file was deleted.

2 changes: 1 addition & 1 deletion www/preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 92e35de

Please sign in to comment.