From 4a4f705adc32831c4e90422598dbe0e89c6acd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 7 Mar 2013 14:15:02 +0100 Subject: [PATCH 1/3] json encode list of files --- apps/files/ajax/download.php | 9 ++++++++- apps/files/js/files.js | 5 +++-- lib/files.php | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php index b9a4ddaf5e..163232ef00 100644 --- a/apps/files/ajax/download.php +++ b/apps/files/ajax/download.php @@ -33,4 +33,11 @@ OCP\User::checkLoggedIn(); $files = $_GET["files"]; $dir = $_GET["dir"]; -OC_Files::get($dir, $files, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); +$files_list = json_decode($files); +if ($files_list === NULL ) { + $files_list = array($files); +} + +foreach ($files_list as $f) error_log("file: $f"); + +OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 464f770368..a4ef41c280 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -220,14 +220,15 @@ $(document).ready(function() { }); $('.download').click('click',function(event) { - var files=getSelectedFiles('name').join(';'); + var files=getSelectedFiles('name'); + var fileslist = JSON.stringify(files); var dir=$('#dir').val()||'/'; OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.')); // use special download URL if provided, e.g. for public shared files if ( (downloadURL = document.getElementById("downloadURL")) ) { window.location=downloadURL.value+"&download&files="+files; } else { - window.location=OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: files }); + window.location=OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist }); } return false; }); diff --git a/lib/files.php b/lib/files.php index b594b78c4b..ae3144de2c 100644 --- a/lib/files.php +++ b/lib/files.php @@ -49,8 +49,9 @@ class OC_Files { isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { $xsendfile = true; } - if(strpos($files, ';')) { - $files=explode(';', $files); + + if (count($files) == 1) { + $files = $files[0]; } if (is_array($files)) { From 3970d1f8750132f73cac4653c9943995ebbb28ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 7 Mar 2013 14:18:27 +0100 Subject: [PATCH 2/3] remove debug output --- apps/files/ajax/download.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php index 163232ef00..7c8dcb372e 100644 --- a/apps/files/ajax/download.php +++ b/apps/files/ajax/download.php @@ -34,10 +34,9 @@ $files = $_GET["files"]; $dir = $_GET["dir"]; $files_list = json_decode($files); +// in case we get only a single file if ($files_list === NULL ) { $files_list = array($files); } -foreach ($files_list as $f) error_log("file: $f"); - OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); From ce9942331eb09b5e1ae6f38791776625f6663419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 7 Mar 2013 14:24:18 +0100 Subject: [PATCH 3/3] create a meanigful file name if files are from the root folder --- lib/files.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/files.php b/lib/files.php index ae3144de2c..447ffb5057 100644 --- a/lib/files.php +++ b/lib/files.php @@ -78,7 +78,13 @@ class OC_Files { } } $zip->close(); - $name = basename($dir) . '.zip'; + $basename = basename($dir); + if ($basename) { + $name = $basename . '.zip'; + } else { + $name = 'owncloud.zip'; + } + set_time_limit($executionTime); } elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) { self::validateZipDownload($dir, $files);