calendarimporter/php/download.php

75 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2013-03-30 14:55:18 +01:00
/**
2016-11-29 19:58:23 +01:00
* download.php, Kopano calendar to ics im/exporter
2013-03-30 14:55:18 +01:00
*
* Author: Christoph Haas <christoph.h@sprinternet.at>
2016-06-20 16:19:05 +02:00
* Copyright (C) 2012-2016 Christoph Haas
2013-03-30 14:55:18 +01:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
2016-06-20 18:02:57 +02:00
namespace calendarimporter;
2016-06-20 16:19:05 +02:00
class DownloadHandler
{
2016-11-29 19:58:23 +01:00
/**
* Download the given vcf file.
* @return boolean
2016-11-29 19:58:23 +01:00
*/
public static function doDownload()
{
if (isset($_GET["token"])) {
$token = $_GET["token"];
} else {
return false;
}
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
if (isset($_GET["filename"])) {
$filename = $_GET["filename"];
} else {
return false;
}
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
// validate token
if (!preg_match('/^[a-zA-Z0-9]+$/', $token)) { // token is a md5 hash
2016-11-29 19:58:23 +01:00
return false;
}
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
$file = PLUGIN_CALENDARIMPORTER_TMP_UPLOAD . "ics_" . $token . ".ics";
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
if (!file_exists($file)) { // invalid token
return false;
}
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
// set headers here
header('Content-Disposition: attachment; filename="' . $filename . '"');
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
// no caching
header('Expires: 0'); // set expiration time
header('Content-Description: File Transfer');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length: ' . filesize($file));
header('Content-Type: application/octet-stream');
header('Pragma: public');
flush();
2016-06-20 16:19:05 +02:00
2016-11-29 19:58:23 +01:00
// print the downloaded file
readfile($file);
ignore_user_abort(true);
unlink($file);
return true;
2016-11-29 19:58:23 +01:00
}
2016-06-20 16:19:05 +02:00
}