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.3KB

  1. <?php
  2. /**
  3. * upload.php, Kopano Webapp contact to vcf im/exporter
  4. *
  5. * Author: Christoph Haas <christoph.h@sprinternet.at>
  6. * Copyright (C) 2012-2016 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. require_once("../config.php");
  24. /* disable error printing - otherwise json communication might break... */
  25. ini_set('display_errors', '0');
  26. /**
  27. * respond/echo JSON
  28. * @param $arr
  29. */
  30. function respondJSON($arr)
  31. {
  32. echo json_encode($arr);
  33. }
  34. /**
  35. * Generates a random string with variable length.
  36. * @param $length the lenght of the generated string
  37. * @return string a random string
  38. */
  39. function randomstring($length = 6)
  40. {
  41. // $chars - all allowed charakters
  42. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  43. srand((double)microtime() * 1000000);
  44. $i = 0;
  45. $pass = "";
  46. while ($i < $length) {
  47. $num = rand() % strlen($chars);
  48. $tmp = substr($chars, $num, 1);
  49. $pass = $pass . $tmp;
  50. $i++;
  51. }
  52. return $pass;
  53. }
  54. $destpath = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD;
  55. $destpath .= $_FILES['vcfdata']['name'] . randomstring();
  56. if (is_readable($_FILES['vcfdata']['tmp_name'])) {
  57. $result = move_uploaded_file($_FILES['vcfdata']['tmp_name'], $destpath);
  58. if ($result) {
  59. respondJSON(array('success' => true, 'vcf_file' => $destpath));
  60. } else {
  61. respondJSON(array('success' => false, 'error' => dgettext("plugin_contactimporter", "File could not be moved to TMP path! Check plugin config and folder permissions!")));
  62. }
  63. } else {
  64. respondJSON(array('success' => false, 'error' => dgettext("plugin_contactimporter", "File could not be read by server, upload error!")));
  65. }
  66. ?>