diff options
Diffstat (limited to 'apps/files/ajax/upload.php')
-rw-r--r-- | apps/files/ajax/upload.php | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index b960e02ced7..fcee0166da6 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -1,5 +1,7 @@ <?php +\OC::$server->getSession()->close(); + // Firefox and Konqueror tries to download application/json for me. --Arthur OCP\JSON::setContentTypeHeader('text/plain'); @@ -7,7 +9,7 @@ OCP\JSON::setContentTypeHeader('text/plain'); // If not, check the login. // If no token is sent along, rely on login only -$allowedPermissions = OCP\PERMISSION_ALL; +$allowedPermissions = \OCP\Constants::PERMISSION_ALL; $errorCode = null; $l = \OC::$server->getL10N('files'); @@ -27,7 +29,7 @@ if (empty($_POST['dirToken'])) { \OC_User::setIncognitoMode(true); // return only read permissions for public upload - $allowedPermissions = OCP\PERMISSION_READ; + $allowedPermissions = \OCP\Constants::PERMISSION_READ; $publicDirectory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/'; $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); @@ -36,7 +38,7 @@ if (empty($_POST['dirToken'])) { die(); } - if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { + if (!($linkItem['permissions'] & \OCP\Constants::PERMISSION_CREATE)) { OCP\JSON::checkLoggedIn(); } else { // resolve reshares @@ -64,13 +66,7 @@ if (empty($_POST['dirToken'])) { } } - OCP\JSON::callCheck(); -if (!\OCP\App::isEnabled('files_encryption')) { - // encryption app need to create keys later, so can't close too early - \OC::$server->getSession()->close(); -} - // get array with current storage stats (e.g. max file size) $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); @@ -121,6 +117,12 @@ if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { + if (isset($_POST['resolution'])) { + $resolution = $_POST['resolution']; + } else { + $resolution = null; + } + // target directory for when uploading folders $relativePath = ''; if(!empty($_POST['file_directory'])) { @@ -128,7 +130,7 @@ if (strpos($dir, '..') === false) { } // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder - if (isset($_POST['resolution']) && $_POST['resolution']==='autorename') { + if ($resolution === 'autorename') { // append a number in brackets like 'filename (2).ext' $target = OCP\Files::buildNotExistingFileName(stripslashes($dir . $relativePath), $files['name'][$i]); } else { @@ -145,9 +147,12 @@ if (strpos($dir, '..') === false) { } $returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir); - if ( ! \OC\Files\Filesystem::file_exists($target) - || (isset($_POST['resolution']) && $_POST['resolution']==='replace') - ) { + + $exists = \OC\Files\Filesystem::file_exists($target); + if ($exists) { + $updatable = \OC\Files\Filesystem::isUpdatable($target); + } + if ( ! $exists || ($updatable && $resolution === 'replace' ) ) { // upload and overwrite file try { @@ -185,8 +190,11 @@ if (strpos($dir, '..') === false) { $error = $l->t('Upload failed. Could not get file info.'); } else { $data = \OCA\Files\Helper::formatFileInfo($meta); - $data['permissions'] = $data['permissions'] & $allowedPermissions; - $data['status'] = 'existserror'; + if ($updatable) { + $data['status'] = 'existserror'; + } else { + $data['status'] = 'readonly'; + } $data['originalname'] = $files['tmp_name'][$i]; $data['uploadMaxFilesize'] = $maxUploadFileSize; $data['maxHumanFilesize'] = $maxHumanFileSize; |