Path().'/'.$Event->DefaultVideo(); Logger::Debug("Path: $path"); } else if ( ! empty($_REQUEST['event_id'] ) ) { $Event = new Event( $_REQUEST['event_id'] ); $path = $Event->Path().'/'.$Event->DefaultVideo(); Logger::Debug("Path: $path"); } else { $errorText = 'No video path'; } if ( $errorText ) { Error( $errorText ); header('HTTP/1.0 404 Not Found'); die(); } $size = filesize($path); $fh = @fopen($path,'rb'); if ( ! $fh ) { header('HTTP/1.0 404 Not Found'); die(); } $begin = 0; $end = $size-1; $length = $size; if ( isset( $_SERVER['HTTP_RANGE'] ) ) { 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]) ) { $end = intval( $matches[2] ); } $length = $end - $begin + 1; Logger::Debug("Using Range $begin $end size: $size, length: $length"); } } # end if HTTP_RANGE header('Content-type: video/mp4'); header('Accept-Ranges: bytes'); header('Content-Length: '.$length); # This is so that Save Image As give a useful filename if ( $Event ) { header('Content-Disposition: inline; filename="' . $Event->DefaultVideo() . '"'); } else { header('Content-Disposition: inline;'); } if ( $begin > 0 || $end < $size-1 ) { header('HTTP/1.0 206 Partial Content'); header("Content-Range: bytes $begin-$end/$size"); header("Content-Transfer-Encoding: binary\n"); header('Connection: close'); } else { header('HTTP/1.0 200 OK'); } // Apparently without these we get a few extra bytes of output at the end... ob_clean(); flush(); $cur = $begin; fseek( $fh, $begin, 0 ); while( $length && ( ! feof( $fh ) ) && ( connection_status() == 0 ) ) { $amount = min( 1024*16, $length ); print fread( $fh, $amount ); $length -= $amount; # Why introduce a speed limit? #usleep(100); flush(); } fclose( $fh ); exit();