public function download($params)
{
if (!is_admin()) {
mw_error('must be admin');
}
ini_set('memory_limit', '512M');
set_time_limit(0);
if (isset($params['id'])) {
$id = $params['id'];
} elseif (isset($_GET['filename'])) {
$id = $params['filename'];
} elseif (isset($_GET['file'])) {
$id = $params['file'];
}
$id = str_replace('..', '', $id);
// Check if the file has needed args
if ($id == null) {
return array('error' => 'You have not provided filename to download.');
die;
}
$here = $this->get_bakup_location();
// Generate filename and set error variables
$filename = $here . $id;
$filename = str_replace('..', '', $filename);
if (!is_file($filename)) {
return array('error' => 'You have not provided a existing filename to download.');
die;
}
// Check if the file exist.
if (file_exists($filename)) {
// Add headers
$name = basename($filename);
$type = 'sql';
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $name);
header('Content-Length: ' . filesize($filename));
// Read file
$this->readfile_chunked($filename);
} else {
die('File does not exist');
}
}