示例#1
0
        exit;
    } else {
        bailOut($l10n->t('Error uploading contacts to storage.'));
    }
}
// File input transfers are handled here
if (!isset($_FILES['importfile'])) {
    OCP\Util::writeLog('contacts', 'ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
    OCP\JSON::error(array('
		data' => array('message' => 'No file was uploaded. Unknown error')));
    exit;
}
$error = $_FILES['importfile']['error'];
if ($error !== UPLOAD_ERR_OK) {
    $errors = array(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"));
    bailOut($errors[$error]);
}
$file = $_FILES['importfile'];
if (file_exists($file['tmp_name'])) {
    $filename = strtr($file['name'], array('/' => '', "\\" => ''));
    if (OC\Files\Filesystem::isFileBlacklisted($filename)) {
        bailOut($l10n->t('Upload of blacklisted file:') . $filename);
    }
    if ($view->file_put_contents('/imports/' . $filename, file_get_contents($file['tmp_name']))) {
        OCP\JSON::success(array('data' => array('file' => $filename, 'name' => $filename)));
    } else {
        bailOut($l10n->t('Error uploading contacts to storage.'));
    }
} else {
    bailOut('Temporary file: \'' . $file['tmp_name'] . '\' has gone AWOL?');
}
示例#2
0
$nl = "\n";
global $progresskey;
$progresskey = 'contacts.import-' . (isset($_GET['progresskey']) ? $_GET['progresskey'] : '');
if (isset($_GET['progress']) && $_GET['progress']) {
    echo OC_Cache::get($progresskey);
    die;
}
function writeProgress($pct)
{
    global $progresskey;
    OC_Cache::set($progresskey, $pct, 300);
}
writeProgress('10');
$view = null;
$inputfile = strtr($_POST['file'], array('/' => '', "\\" => ''));
if (OC\Files\Filesystem::isFileBlacklisted($inputfile)) {
    OCP\JSON::error(array('data' => array('message' => 'Upload of blacklisted file: ' . $inputfile)));
    exit;
}
if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
    $view = OCP\Files::getStorage('contacts');
    $file = $view->file_get_contents('/imports/' . $inputfile);
} else {
    $file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $inputfile);
}
if (!$file) {
    OCP\JSON::error(array('data' => array('message' => 'Import file was empty.')));
    exit;
}
if (isset($_POST['method']) && $_POST['method'] == 'new') {
    $id = OCA\Contacts\Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);