]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed uploading by drag and drop into folder
authorVincent Petry <pvince81@owncloud.com>
Wed, 18 Jun 2014 18:38:51 +0000 (20:38 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 19 Jun 2014 14:14:10 +0000 (16:14 +0200)
apps/files/ajax/upload.php
apps/files/js/file-upload.js
apps/files/js/filelist.js
apps/files_sharing/js/public.js

index 9750173d1107f587f0329c6197398f9cdccd071b..f9fcfaf13c5ca1e4896688eea53020e7c3b10649 100644 (file)
@@ -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;
                        }
                }
index 6b0ca793681089edd304deae6ae05d531546b15e..da58e1c31b8c1690496605d7ea15390566f643a0 100644 (file)
@@ -346,7 +346,7 @@ OC.Upload = {
                                                // noone set update parameters, we set the minimum
                                                data.formData = {
                                                        requesttoken: oc_requesttoken,
-                                                       dir: FileList.getCurrentDirectory(),
+                                                       dir: data.targetDir || FileList.getCurrentDirectory(),
                                                        file_directory: fileDirectory
                                                };
                                        }
index 85c5d3f1bb0216b064c8f3669d6fc12f3787bda7..cb6c3dcb2c06fda9135e432dba4e3b7a00f64540 100644 (file)
                                                dir = dropTarget.data('dir') || '/';
                                        }
 
-                                       // update folder in form
-                                       data.formData = function() {
-                                               return [
-                                                       {name: 'dir', value: dir},
-                                                       {name: 'requesttoken', value: oc_requesttoken},
-                                                       {name: 'file_directory', value: data.files[0].relativePath}
-                                               ];
-                                       };
+                                       // add target dir
+                                       data.targetDir = dir;
                                } else {
                                        // we are dropping somewhere inside the file list, which will
                                        // upload the file to the current directory
+                                       data.targetDir = self.getCurrentDirectory();
 
                                        // cancel uploads to current dir if no permission
                                        var isCreatable = (self.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0;
index 80631908d24df715e6b145162d3c8c139e7f1fc9..1d633a655d5a2760f7d597a284940d312bf92ca8 100644 (file)
@@ -128,7 +128,7 @@ OCA.Sharing.PublicApp = {
                                data.formData = {
                                        requesttoken: $('#publicUploadRequestToken').val(),
                                        dirToken: $('#dirToken').val(),
-                                       subdir: self.fileList.getCurrentDirectory(),
+                                       subdir: data.targetDir || self.fileList.getCurrentDirectory(),
                                        file_directory: fileDirectory
                                };
                        });