Merge pull request #536 from radiorabe/dev/fileio-for-sizeless-files-from-legacy

Always return proper file size
This commit is contained in:
Robb 2018-10-06 17:11:16 -04:00 committed by GitHub
commit 022b231cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -26,8 +26,16 @@ class Application_Common_FileIO
} }
//Note that $size is allowed to be zero. If that's the case, it means we don't //Note that $size is allowed to be zero. If that's the case, it means we don't
//know the filesize, and we just won't send the Content-Length header. //know the filesize, and we need to figure one out so modern browsers don't get
if ($size < 0) { //confused. This should only affect files imported by legacy upstream since
//media monitor did not always set the proper size in the database but analyzer
//seems to always have a value for this.
if ($size === 0) {
$fstats = fstat($fm);
$size = $fstats['size'];
}
if ($size <= 0) {
throw new Exception("Invalid file size returned for file at $filePath"); throw new Exception("Invalid file size returned for file at $filePath");
} }
@ -56,11 +64,9 @@ class Application_Common_FileIO
header('Cache-Control: public, must-revalidate, max-age=0'); header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache'); header('Pragma: no-cache');
header('Accept-Ranges: bytes'); header('Accept-Ranges: bytes');
if ($size > 0) { header('Content-Length:' . (($end - $begin) + 1));
header('Content-Length:' . (($end - $begin) + 1)); if (isset($_SERVER['HTTP_RANGE'])) {
if (isset($_SERVER['HTTP_RANGE'])) { header("Content-Range: bytes $begin-$end/$size");
header("Content-Range: bytes $begin-$end/$size");
}
} }
//We can have multiple levels of output buffering. Need to //We can have multiple levels of output buffering. Need to