The contact importer and exporter plugin for the Kopano WebApp. See here for more details: https://community.zarafa.com/pg/plugins/project/20393/developer/h44z/webapp-contact-importer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2KB

  1. <?php
  2. /**
  3. * download.php, Kopano Webapp contact to vcf im/exporter
  4. *
  5. * Author: Christoph Haas <christoph.h@sprinternet.at>
  6. * Copyright (C) 2012-2018 Christoph Haas
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. class DownloadHandler
  24. {
  25. /**
  26. * Download the given vcf file.
  27. * @return boolean
  28. */
  29. public static function doDownload()
  30. {
  31. if (isset($_GET["token"])) {
  32. $token = $_GET["token"];
  33. } else {
  34. return false;
  35. }
  36. if (isset($_GET["filename"])) {
  37. $filename = $_GET["filename"];
  38. } else {
  39. return false;
  40. }
  41. // validate token
  42. if (!preg_match('/^[a-zA-Z0-9]+$/', $token)) { // token is a md5 hash
  43. return false;
  44. }
  45. $file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf";
  46. if (!file_exists($file)) { // invalid token
  47. return false;
  48. }
  49. // set headers here
  50. header('Content-Disposition: attachment; filename="' . $filename . '"');
  51. // no caching
  52. header('Expires: 0'); // set expiration time
  53. header('Content-Description: File Transfer');
  54. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  55. header('Content-Length: ' . filesize($file));
  56. header('Content-Type: application/octet-stream');
  57. header('Pragma: public');
  58. flush();
  59. // print the downloaded file
  60. readfile($file);
  61. ignore_user_abort(true);
  62. unlink($file);
  63. return true;
  64. }
  65. }