summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax/upload.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-06-18 20:38:51 +0200
committerVincent Petry <pvince81@owncloud.com>2014-06-19 16:14:10 +0200
commit9ef7410abe282e2a81a9cd41672574a74282e4c3 (patch)
treeb1a0fe6b1a2724eab86f65fb3f859194b2788036 /apps/files/ajax/upload.php
parenta921ad89259f1d580292d649a58160fab7a2a2d7 (diff)
downloadnextcloud-server-9ef7410abe282e2a81a9cd41672574a74282e4c3.tar.gz
nextcloud-server-9ef7410abe282e2a81a9cd41672574a74282e4c3.zip
Fixed uploading by drag and drop into folder
Diffstat (limited to 'apps/files/ajax/upload.php')
-rw-r--r--apps/files/ajax/upload.php40
1 files changed, 21 insertions, 19 deletions
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index 9750173d110..f9fcfaf13c5 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -26,7 +26,7 @@ if (empty($_POST['dirToken'])) {
// return only read permissions for public upload
$allowedPermissions = OCP\PERMISSION_READ;
- $public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/';
+ $publicDirectory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/';
$linkItem = OCP\Share::getShareByToken($_POST['dirToken']);
if ($linkItem === false) {
@@ -50,13 +50,15 @@ if (empty($_POST['dirToken'])) {
$dir = sprintf(
"/%s/%s",
$path,
- $public_directory
+ $publicDirectory
);
if (!$dir || empty($dir) || $dir === false) {
OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.')))));
die();
}
+
+ $dir = rtrim($dir, '/');
}
}
@@ -113,33 +115,33 @@ if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
}
$result = array();
-$directory = '';
if (strpos($dir, '..') === false) {
$fileCount = count($files['name']);
for ($i = 0; $i < $fileCount; $i++) {
- // Get the files directory
- if(isset($_POST['file_directory']) === true) {
- $directory = '/'.$_POST['file_directory'];
+ // target directory for when uploading folders
+ $relativePath = '';
+ if(!empty($_POST['file_directory'])) {
+ $relativePath = '/'.$_POST['file_directory'];
}
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
if (isset($_POST['resolution']) && $_POST['resolution']==='autorename') {
// append a number in brackets like 'filename (2).ext'
- $target = OCP\Files::buildNotExistingFileName(stripslashes($dir.$directory), $files['name'][$i]);
+ $target = OCP\Files::buildNotExistingFileName(stripslashes($dir . $relativePath), $files['name'][$i]);
} else {
- $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir.$directory).'/'.$files['name'][$i]);
+ $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir . $relativePath).'/'.$files['name'][$i]);
}
-
- if(empty($directory) === true)
- {
- $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir));
- if (isset($public_directory)) {
- // If we are uploading from the public app,
- // we want to send the relative path in the ajax request.
- $directory = $public_directory;
- }
+
+ // relative dir to return to the client
+ if (isset($publicDirectory)) {
+ // path relative to the public root
+ $returnedDir = $publicDirectory . $relativePath;
+ } else {
+ // full path
+ $returnedDir = $dir . $relativePath;
}
+ $returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
if ( ! \OC\Files\Filesystem::file_exists($target)
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
@@ -163,7 +165,7 @@ if (strpos($dir, '..') === false) {
$data['uploadMaxFilesize'] = $maxUploadFileSize;
$data['maxHumanFilesize'] = $maxHumanFileSize;
$data['permissions'] = $meta['permissions'] & $allowedPermissions;
- $data['directory'] = $directory;
+ $data['directory'] = $returnedDir;
$result[] = $data;
}
@@ -187,7 +189,7 @@ if (strpos($dir, '..') === false) {
$data['uploadMaxFilesize'] = $maxUploadFileSize;
$data['maxHumanFilesize'] = $maxHumanFileSize;
$data['permissions'] = $meta['permissions'] & $allowedPermissions;
- $data['directory'] = $directory;
+ $data['directory'] = $returnedDir;
$result[] = $data;
}
}