2013-05-20 23:09:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* upload.php, zarafa contact to vcf im/exporter
|
|
|
|
*
|
|
|
|
* Author: Christoph Haas <christoph.h@sprinternet.at>
|
2016-06-13 22:59:05 +02:00
|
|
|
* Copyright (C) 2012-2016 Christoph Haas
|
2013-05-20 23:09:51 +02: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-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
require_once("../config.php");
|
|
|
|
|
|
|
|
/* disable error printing - otherwise json communication might break... */
|
|
|
|
ini_set('display_errors', '0');
|
|
|
|
|
2016-06-13 22:59:05 +02:00
|
|
|
/**
|
|
|
|
* respond/echo JSON
|
|
|
|
* @param $arr
|
|
|
|
*/
|
|
|
|
function respondJSON($arr)
|
|
|
|
{
|
2013-05-20 23:09:51 +02:00
|
|
|
echo json_encode($arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a random string with variable length.
|
|
|
|
* @param $length the lenght of the generated string
|
|
|
|
* @return string a random string
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
function randomstring($length = 6)
|
|
|
|
{
|
2013-05-20 23:09:51 +02:00
|
|
|
// $chars - all allowed charakters
|
|
|
|
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
|
|
|
|
2016-06-13 22:59:05 +02:00
|
|
|
srand((double)microtime() * 1000000);
|
2013-05-20 23:09:51 +02:00
|
|
|
$i = 0;
|
|
|
|
$pass = "";
|
|
|
|
while ($i < $length) {
|
|
|
|
$num = rand() % strlen($chars);
|
|
|
|
$tmp = substr($chars, $num, 1);
|
|
|
|
$pass = $pass . $tmp;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
$destpath = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD;
|
|
|
|
$destpath .= $_FILES['vcfdata']['name'] . randomstring();
|
|
|
|
|
2016-06-13 22:59:05 +02:00
|
|
|
if (is_readable($_FILES['vcfdata']['tmp_name'])) {
|
|
|
|
$result = move_uploaded_file($_FILES['vcfdata']['tmp_name'], $destpath);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
respondJSON(array('success' => true, 'vcf_file' => $destpath));
|
2013-05-20 23:09:51 +02:00
|
|
|
} else {
|
2016-06-13 22:59:05 +02:00
|
|
|
respondJSON(array('success' => false, 'error' => "File could not be moved to TMP path! Check plugin config and folder permissions!"));
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-06-13 22:59:05 +02:00
|
|
|
respondJSON(array('success' => false, 'error' => "File could not be read by server, upload error!"));
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
?>
|