From 7af4cf48c9c542326626d742282aa1958b4b3501 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 16 Nov 2012 10:23:40 +0100 Subject: [PATCH 1/3] refs #461 - drag'n'drop upload to a sub folder is working now --- apps/files/ajax/upload.php | 6 ++++++ apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 17 ++++++++++++++--- lib/filecache.php | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 4ed0bbc5b0..9287105993 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -51,6 +51,12 @@ if(strpos($dir, '..') === false) { if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { $meta = OC_FileCache::get($target); $id = OC_FileCache::getId($target); + // in case the upload goes to a sub directory getID() returns -1 and $target needs to be normalized + // calling normalizePath() inside getId() causes endless scan. + if ($id == -1) { + $path = OC_Filesystem::normalizePath($target); + $id = OC_FileCache::getId($path); + } $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'], 'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target)); } } diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index f754a7cd16..a5550dc992 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -141,7 +141,7 @@ var FileList={ tr=$('tr').filterAttr('data-file',name); tr.data('renaming',true); td=tr.children('td.filename'); - input=$('').val(name); + input=$('').val(name); form=$('
'); form.append(input); td.children('a.name').hide(); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 982351c589..8b3ab06e6f 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -228,7 +228,12 @@ $(document).ready(function() { } }); }else{ - var date=new Date(); + var dropTarget = $(e.originalEvent.target).closest('tr'); + if(dropTarget && dropTarget.attr('data-type') === 'dir') { // drag&drop upload to folder + var dirName = dropTarget.attr('data-file') + } + + var date=new Date(); if(files){ for(var i=0;i0){ @@ -281,7 +286,7 @@ $(document).ready(function() { var jqXHR = $('.file_upload_start').fileupload('send', {files: files[i], formData: function(form) { var formArray = form.serializeArray(); - formArray[1]['value'] = dirName; + formArray[2]['value'] = dirName; return formArray; }}).success(function(result, textStatus, jqXHR) { var response; @@ -291,7 +296,13 @@ $(document).ready(function() { $('#notification').fadeIn(); } var file=response[0]; + // TODO: this doesn't work if the file name has been changed server side delete uploadingFiles[dirName][file.name]; + if ($.assocArraySize(uploadingFiles[dirName]) == 0) { + delete uploadingFiles[dirName]; + } + + var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext') var currentUploads = parseInt(uploadtext.attr('currentUploads')); currentUploads -= 1; uploadtext.attr('currentUploads', currentUploads); @@ -821,7 +832,7 @@ function getSelectedFiles(property){ name:$(element).attr('data-file'), mime:$(element).data('mime'), type:$(element).data('type'), - size:$(element).data('size'), + size:$(element).data('size') }; if(property){ files.push(file[property]); diff --git a/lib/filecache.php b/lib/filecache.php index 4a7dbd0250..2a389dfc3c 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -43,6 +43,8 @@ class OC_FileCache{ * - versioned */ public static function get($path, $root=false) { + // $path needs to be normalized - this failed within drag'n'drop upload to a subfolder + $path = OC_Filesystem::normalizePath($path); if(OC_FileCache_Update::hasUpdated($path, $root)) { if($root===false) {//filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$path)); From 2b192a75c41c1ef1d02677cd08f5781a54391509 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 16 Nov 2012 11:50:57 +0100 Subject: [PATCH 2/3] normalize the path once in upload.php is enough - THX Robin for this hint --- apps/files/ajax/upload.php | 8 ++------ lib/filecache.php | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 9287105993..c3d3199a00 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -48,15 +48,11 @@ if(strpos($dir, '..') === false) { $fileCount=count($files['name']); for($i=0;$i<$fileCount;$i++) { $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); + // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder + $target = OC_Filesystem::normalizePath($target); if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { $meta = OC_FileCache::get($target); $id = OC_FileCache::getId($target); - // in case the upload goes to a sub directory getID() returns -1 and $target needs to be normalized - // calling normalizePath() inside getId() causes endless scan. - if ($id == -1) { - $path = OC_Filesystem::normalizePath($target); - $id = OC_FileCache::getId($path); - } $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'], 'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target)); } } diff --git a/lib/filecache.php b/lib/filecache.php index 2a389dfc3c..4a7dbd0250 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -43,8 +43,6 @@ class OC_FileCache{ * - versioned */ public static function get($path, $root=false) { - // $path needs to be normalized - this failed within drag'n'drop upload to a subfolder - $path = OC_Filesystem::normalizePath($path); if(OC_FileCache_Update::hasUpdated($path, $root)) { if($root===false) {//filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$path)); From 4a3b5125cfb4f35d8a40597aca200d0d37d494dd Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 16 Nov 2012 11:58:33 +0100 Subject: [PATCH 3/3] adding comments on the form array indexes --- apps/files/js/files.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8b3ab06e6f..bb80841055 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -286,6 +286,9 @@ $(document).ready(function() { var jqXHR = $('.file_upload_start').fileupload('send', {files: files[i], formData: function(form) { var formArray = form.serializeArray(); + // array index 0 contains the max files size + // array index 1 contains the request token + // array index 2 contains the directory formArray[2]['value'] = dirName; return formArray; }}).success(function(result, textStatus, jqXHR) {