reorganize to reduce code depth

This commit is contained in:
Isaac Connor 2020-04-10 12:21:53 -04:00
parent bdfdc2a20c
commit d99ec696b4
1 changed files with 28 additions and 28 deletions

View File

@ -1,6 +1,6 @@
<?php
//
// ZoneMinder file view file, $Date: 2008-09-29 14:15:13 +0100 (Mon, 29 Sep 2008) $, $Revision: 2640 $
// ZoneMinder file view file
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
@ -23,11 +23,13 @@ if ( !canView('Events') ) {
return;
}
$archivetype = $_REQUEST['type'];
$connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:'';
$archivetype = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
if ( !$archivetype ) {
ZM\Error('No archive type given to archive.php. Please specify a tar or zip archive.');
return;
}
if ( $archivetype ) {
switch ($archivetype) {
switch ($archivetype) {
case 'tar.gz':
$mimetype = 'gzip';
$file_ext = 'tar.gz';
@ -43,31 +45,29 @@ if ( $archivetype ) {
default:
$mimetype = NULL;
$file_ext = NULL;
}
}
if ( $mimetype ) {
$filename = "zmExport_$connkey.$file_ext";
$filename_path = ZM_DIR_EXPORTS.'/'.$filename;
ZM\Logger::Debug("downloading archive from $filename_path");
if ( is_readable($filename_path) ) {
while (ob_get_level()) {
ZM\Logger::Debug('Clearing ob');
ob_end_clean();
}
header("Content-type: application/$mimetype" );
header("Content-Disposition: inline; filename=$filename");
header('Content-Length: '.filesize($filename_path));
set_time_limit(0);
if ( ! @readfile($filename_path) ) {
ZM\Error("Error sending $filename_path");
}
} else {
ZM\Error("$filename_path does not exist or is not readable.");
}
} else {
ZM\Error('Unsupported archive type specified. Supported archives are tar and zip');
if ( !$mimetype ) {
ZM\Error('Unsupported archive type specified. Supported archives are tar and zip');
return;
}
$connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:'';
$filename = "zmExport_$connkey.$file_ext";
$filename_path = ZM_DIR_EXPORTS.'/'.$filename;
ZM\Logger::Debug("downloading archive from $filename_path");
if ( is_readable($filename_path) ) {
while (ob_get_level()) {
ob_end_clean();
}
header("Content-type: application/$mimetype");
header("Content-Disposition: inline; filename=$filename");
header('Content-Length: '.filesize($filename_path));
set_time_limit(0);
if ( !@readfile($filename_path) ) {
ZM\Error("Error sending $filename_path");
}
} else {
ZM\Error('No archive type given to archive.php. Please specify a tar or zip archive.');
ZM\Error($filename_path.' does not exist or is not readable.');
}
?>