Skip to content
Snippets Groups Projects
Select Git revision
  • f551917a3ca2cedf748337646ed4b1d398ac8437
  • master default protected
2 results

upload.php

Blame
  • upload.php 8.38 KiB
    <?php
    /**
     * @author Arthur Schiwon <blizzz@owncloud.com>
     * @author Bart Visscher <bartv@thisnet.nl>
     * @author Bjoern Schiessle <schiessle@owncloud.com>
     * @author Florian Pritz <bluewind@xinu.at>
     * @author Frank Karlitschek <frank@owncloud.org>
     * @author Joas Schilling <nickvergessen@gmx.de>
     * @author Jörn Friedrich Dreyer <jfd@butonic.de>
     * @author Lukas Reschke <lukas@owncloud.com>
     * @author Luke Policinski <lpolicinski@gmail.com>
     * @author Robin Appelman <icewind@owncloud.com>
     * @author Roman Geber <rgeber@owncloudapps.com>
     * @author TheSFReader <TheSFReader@gmail.com>
     * @author Thomas Müller <thomas.mueller@tmit.eu>
     * @author Vincent Petry <pvince81@owncloud.com>
     *
     * @copyright Copyright (c) 2015, ownCloud, Inc.
     * @license AGPL-3.0
     *
     * This code is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License, version 3,
     * as published by the Free Software Foundation.
     *
     * This program 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, version 3,
     * along with this program.  If not, see <http://www.gnu.org/licenses/>
     *
     */
    \OC::$server->getSession()->close();
    
    // Firefox and Konqueror tries to download application/json for me.  --Arthur
    OCP\JSON::setContentTypeHeader('text/plain');
    
    // If a directory token is sent along check if public upload is permitted.
    // If not, check the login.
    // If no token is sent along, rely on login only
    
    $allowedPermissions = \OCP\Constants::PERMISSION_ALL;
    $errorCode = null;
    
    $l = \OC::$server->getL10N('files');
    if (empty($_POST['dirToken'])) {
    	// The standard case, files are uploaded through logged in users :)
    	OCP\JSON::checkLoggedIn();
    	$dir = isset($_POST['dir']) ? (string)$_POST['dir'] : '';
    	if (!$dir || empty($dir) || $dir === false) {
    		OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.')))));
    		die();
    	}
    } else {
    	// TODO: ideally this code should be in files_sharing/ajax/upload.php
    	// and the upload/file transfer code needs to be refactored into a utility method
    	// that could be used there
    
    	\OC_User::setIncognitoMode(true);
    
    	// return only read permissions for public upload
    	$allowedPermissions = \OCP\Constants::PERMISSION_READ;
    	$publicDirectory = !empty($_POST['subdir']) ? (string)$_POST['subdir'] : '/';
    
    	$linkItem = OCP\Share::getShareByToken((string)$_POST['dirToken']);
    	if ($linkItem === false) {
    		OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Invalid Token')))));
    		die();
    	}