1<?php 2// 3// ZoneMinder file view file 4// Copyright (C) 2001-2008 Philip Coombes 5// 6// This program is free software; you can redistribute it and/or 7// modify it under the terms of the GNU General Public License 8// as published by the Free Software Foundation; either version 2 9// of the License, or (at your option) any later version. 10// 11// This program is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15// 16// You should have received a copy of the GNU General Public License 17// along with this program; if not, write to the Free Software 18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19// 20 21if ( !canView('Events') ) { 22 $view = 'error'; 23 return; 24} 25 26$archivetype = isset($_REQUEST['type']) ? $_REQUEST['type'] : ''; 27if ( !$archivetype ) { 28 ZM\Error('No archive type given to archive.php. Please specify a tar or zip archive.'); 29 return; 30} 31 32switch ($archivetype) { 33 case 'tar.gz': 34 $mimetype = 'gzip'; 35 $file_ext = 'tar.gz'; 36 break; 37 case 'tar': 38 $mimetype = 'tar'; 39 $file_ext = 'tar'; 40 break; 41 case 'zip': 42 $mimetype = 'zip'; 43 $file_ext = 'zip'; 44 break; 45 default: 46 $mimetype = NULL; 47 $file_ext = NULL; 48} 49 50if ( !$mimetype ) { 51 ZM\Error('Unsupported archive type specified. Supported archives are tar and zip'); 52 return; 53} 54 55$connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''; 56$filename = "zmExport_$connkey.$file_ext"; 57$filename_path = ZM_DIR_EXPORTS.'/'.$filename; 58ZM\Debug("downloading archive from $filename_path"); 59if ( is_readable($filename_path) ) { 60 while (ob_get_level()) { 61 ob_end_clean(); 62 } 63 header("Content-type: application/$mimetype"); 64 header("Content-Disposition: inline; filename=$filename"); 65 header('Content-Length: '.filesize($filename_path)); 66 set_time_limit(0); 67 if ( !@readfile($filename_path) ) { 68 ZM\Error("Error sending $filename_path"); 69 } 70} else { 71 ZM\Error($filename_path.' does not exist or is not readable.'); 72} 73?> 74