2013-05-20 23:09:51 +02:00
< ? php
2016-11-30 12:31:42 +01:00
2013-05-20 23:09:51 +02:00
/**
2016-11-29 15:24:22 +01:00
* upload . php , Kopano Webapp contact to vcf im / exporter
2013-05-20 23:09:51 +02:00
*
* 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
2016-11-30 12:31:42 +01:00
require_once ( __DIR__ . " /../config.php " );
require_once ( __DIR__ . " /helper.php " );
2013-05-20 23:09:51 +02:00
2016-11-30 12:31:42 +01:00
require_once ( __DIR__ . '/../../../init.php' );
require_once ( __DIR__ . " /../../../server/includes/core/class.webappauthentication.php " ); // for checking the session
2013-05-20 23:09:51 +02:00
2016-11-30 12:31:42 +01:00
use contactimporter\Helper ;
2013-05-20 23:09:51 +02:00
2016-11-30 12:31:42 +01:00
/* disable error printing - otherwise json communication might break... */
ini_set ( 'display_errors' , '0' );
2013-05-20 23:09:51 +02:00
2016-11-30 12:31:42 +01:00
// check session
// otherwise a DOS attack might be possible
if ( ! WebAppAuthentication :: getUserName () || WebAppAuthentication :: getUserName () == " " ) {
Helper :: respondJSON ( array ( 'success' => false , 'error' => dgettext ( " plugin_contactimporter " , " Not authenticated! " )));
die ();
2013-05-20 23:09:51 +02:00
}
2016-06-13 22:59:05 +02:00
if ( is_readable ( $_FILES [ 'vcfdata' ][ 'tmp_name' ])) {
2016-11-30 12:31:42 +01:00
$dstPath = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD ;
$dstPath .= $_FILES [ 'vcfdata' ][ 'name' ] . Helper :: randomstring ();
$result = move_uploaded_file ( $_FILES [ 'vcfdata' ][ 'tmp_name' ], $dstPath );
2016-06-13 22:59:05 +02:00
2016-11-29 15:24:22 +01:00
if ( $result ) {
2016-11-30 12:31:42 +01:00
Helper :: respondJSON ( array ( 'success' => true , 'vcf_file' => $dstPath ));
2016-11-29 15:24:22 +01:00
} else {
2016-11-30 12:31:42 +01:00
Helper :: respondJSON ( array ( 'success' => false , 'error' => dgettext ( " plugin_contactimporter " , " File could not be moved to TMP path! Check plugin config and folder permissions! " )));
2016-11-29 15:24:22 +01:00
}
2013-05-20 23:09:51 +02:00
} else {
2016-11-30 12:31:42 +01:00
Helper :: respondJSON ( array ( 'success' => false , 'error' => dgettext ( " plugin_contactimporter " , " File could not be read by server, upload error! " )));
2016-11-29 15:51:38 +01:00
}