2012-04-23 21:14:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud - Addressbook
|
|
|
|
*
|
|
|
|
* @author Thomas Tanghus
|
|
|
|
* @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check if we are a user
|
2012-05-03 12:23:29 +02:00
|
|
|
OCP\JSON::checkLoggedIn();
|
|
|
|
OCP\JSON::checkAppEnabled('contacts');
|
2012-07-05 00:37:08 +02:00
|
|
|
OCP\JSON::callCheck();
|
2012-07-19 23:48:17 +02:00
|
|
|
require_once 'loghandler.php';
|
|
|
|
|
2012-10-25 03:34:12 +02:00
|
|
|
$l10n = OCA\Contacts\App::$l10n;
|
2012-04-23 21:14:10 +02:00
|
|
|
|
2012-05-19 10:44:08 +02:00
|
|
|
$view = OCP\Files::getStorage('contacts');
|
2012-07-15 04:15:57 +02:00
|
|
|
if(!$view->file_exists('imports')) {
|
|
|
|
$view->mkdir('imports');
|
|
|
|
}
|
2012-04-26 03:20:28 +02:00
|
|
|
$tmpfile = md5(rand());
|
|
|
|
|
2012-04-23 21:14:10 +02:00
|
|
|
// If it is a Drag'n'Drop transfer it's handled here.
|
|
|
|
$fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
|
2013-03-09 16:30:09 +01:00
|
|
|
$fn = strtr($fn, array('/' => '', "\\" => ''));
|
2012-04-23 21:14:10 +02:00
|
|
|
if($fn) {
|
2013-03-09 14:55:05 +01:00
|
|
|
if(OC\Files\Filesystem::isFileBlacklisted($fn)) {
|
|
|
|
bailOut($l10n->t('Upload of blacklisted file:') . $fn);
|
|
|
|
}
|
2012-07-15 04:15:57 +02:00
|
|
|
if($view->file_put_contents('/imports/'.$fn, file_get_contents('php://input'))) {
|
|
|
|
OCP\JSON::success(array('data' => array('file'=>$tmpfile, 'name'=>$fn)));
|
2012-04-26 03:20:28 +02:00
|
|
|
exit();
|
2012-04-23 21:14:10 +02:00
|
|
|
} else {
|
2012-07-19 23:48:17 +02:00
|
|
|
bailOut($l10n->t('Error uploading contacts to storage.'));
|
2012-04-23 21:14:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 03:20:28 +02:00
|
|
|
// File input transfers are handled here
|
|
|
|
if (!isset($_FILES['importfile'])) {
|
2012-07-19 23:48:17 +02:00
|
|
|
OCP\Util::writeLog('contacts',
|
2012-09-07 14:32:45 +02:00
|
|
|
'ajax/uploadphoto.php: No file was uploaded. Unknown error.',
|
2012-07-19 23:48:17 +02:00
|
|
|
OCP\Util::DEBUG);
|
|
|
|
OCP\JSON::error(array('
|
|
|
|
data' => array(
|
|
|
|
'message' => 'No file was uploaded. Unknown error' )));
|
2012-04-26 03:20:28 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$error = $_FILES['importfile']['error'];
|
|
|
|
if($error !== UPLOAD_ERR_OK) {
|
|
|
|
$errors = array(
|
2012-07-19 23:48:17 +02:00
|
|
|
0=>$l10n->t("There is no error, the file uploaded with success"),
|
|
|
|
1=>$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
|
|
|
|
2=>$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
|
|
|
|
3=>$l10n->t("The uploaded file was only partially uploaded"),
|
|
|
|
4=>$l10n->t("No file was uploaded"),
|
|
|
|
6=>$l10n->t("Missing a temporary folder")
|
2012-04-26 03:20:28 +02:00
|
|
|
);
|
|
|
|
bailOut($errors[$error]);
|
|
|
|
}
|
|
|
|
$file=$_FILES['importfile'];
|
|
|
|
|
|
|
|
if(file_exists($file['tmp_name'])) {
|
2013-03-09 16:30:09 +01:00
|
|
|
$filename = strtr($file['name'], array('/' => '', "\\" => ''));
|
|
|
|
if(OC\Files\Filesystem::isFileBlacklisted($filename)) {
|
|
|
|
bailOut($l10n->t('Upload of blacklisted file:') . $filename);
|
2013-03-09 14:55:05 +01:00
|
|
|
}
|
2013-03-09 16:30:09 +01:00
|
|
|
if($view->file_put_contents('/imports/'.$filename, file_get_contents($file['tmp_name']))) {
|
|
|
|
OCP\JSON::success(array('data' => array('file'=>$filename, 'name'=>$filename)));
|
2012-04-26 03:20:28 +02:00
|
|
|
} else {
|
2012-07-19 23:48:17 +02:00
|
|
|
bailOut($l10n->t('Error uploading contacts to storage.'));
|
2012-04-26 03:20:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bailOut('Temporary file: \''.$file['tmp_name'].'\' has gone AWOL?');
|
|
|
|
}
|