Test for opening file before getting it's size. Remove some debug in view_video

This commit is contained in:
Isaac Connor 2020-04-17 09:45:40 -04:00
parent b74d8d7487
commit 7d4e1fe895
1 changed files with 7 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<?php
//
// ZoneMinder web video view file, $Date: 2008-09-29 14:15:13 +0100 (Mon, 29 Sep 2008) $, $Revision: 2640 $
// ZoneMinder web video view file
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
@ -40,11 +40,9 @@ $Event = null;
if ( ! empty($_REQUEST['eid']) ) {
$Event = new ZM\Event($_REQUEST['eid']);
$path = $Event->Path().'/'.$Event->DefaultVideo();
ZM\Logger::Debug("Path: $path");
} else if ( ! empty($_REQUEST['event_id']) ) {
$Event = new ZM\Event($_REQUEST['event_id']);
$path = $Event->Path().'/'.$Event->DefaultVideo();
ZM\Logger::Debug("Path: $path");
} else {
$errorText = 'No video path';
}
@ -55,23 +53,21 @@ if ( $errorText ) {
die();
}
$size = filesize($path);
$fh = @fopen($path,'rb');
if ( ! $fh ) {
if ( ! ($fh = @fopen($path,'rb') ) ) {
header('HTTP/1.0 404 Not Found');
die();
}
$size = filesize($path);
$begin = 0;
$end = $size-1;
$length = $size;
if ( isset($_SERVER['HTTP_RANGE']) ) {
ZM\Logger::Debug('Using Range ' . $_SERVER['HTTP_RANGE']);
ZM\Logger::Debug('Using Range '.$_SERVER['HTTP_RANGE']);
if ( preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches) ) {
$begin = intval($matches[1]);
if ( ! empty($matches[2]) ) {
if ( !empty($matches[2]) ) {
$end = intval($matches[2]);
}
$length = $end - $begin + 1;
@ -103,10 +99,10 @@ flush();
$cur = $begin;
fseek($fh, $begin, 0);
while( $length && ( !feof($fh) ) && ( connection_status() == 0 ) ) {
while ( $length && ( !feof($fh) ) && ( connection_status() == 0 ) ) {
$amount = min(1024*16, $length);
print fread( $fh, $amount );
print fread($fh, $amount);
$length -= $amount;
# Why introduce a speed limit?
#usleep(100);