summaryrefslogtreecommitdiffstats
path: root/lib/files.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2012-03-16 16:25:15 +0100
committerArthur Schiwon <blizzz@owncloud.com>2012-03-16 16:25:15 +0100
commita77edf88c6da02456569b2810830c19f7d2648b3 (patch)
tree8097700f8203206a1a53543393169e7c737d48eb /lib/files.php
parentcfc41942e443a585e549d194f2411586df18f450 (diff)
downloadnextcloud-server-a77edf88c6da02456569b2810830c19f7d2648b3.tar.gz
nextcloud-server-a77edf88c6da02456569b2810830c19f7d2648b3.zip
check if selected files for zip archive are not too large
offer config option
Diffstat (limited to 'lib/files.php')
-rw-r--r--lib/files.php44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/files.php b/lib/files.php
index 1f8331afb21..50223df1d36 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -59,6 +59,9 @@ class OC_Files {
}
if(is_array($files)){
+ self::checkZipInputSize($dir,$files);
+ $executionTime = intval(ini_get('max_execution_time'));
+ set_time_limit(0);
$zip = new ZipArchive();
$filename = get_temp_dir()."/ownCloud.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
@@ -75,7 +78,11 @@ class OC_Files {
}
}
$zip->close();
+ set_time_limit($executionTime);
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
+ self::checkZipInputSize($dir,$files);
+ $executionTime = intval(ini_get('max_execution_time'));
+ set_time_limit(0);
$zip = new ZipArchive();
$filename = get_temp_dir()."/ownCloud.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
@@ -84,6 +91,7 @@ class OC_Files {
$file=$dir.'/'.$files;
self::zipAddDir($file,$zip);
$zip->close();
+ set_time_limit($executionTime);
}else{
$zip=false;
$filename=$dir.'/'.$files;
@@ -210,6 +218,40 @@ class OC_Files {
}
/**
+ * checks if the selected files are within the size constraint. If not, outputs an error page.
+ *
+ * @param dir $dir
+ * @param files $files
+ */
+ static function checkZipInputSize($dir, $files) {
+ $zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
+ if($zipLimit > 0) {
+ $totalsize = 0;
+ if(is_array($files)){
+ foreach($files as $file){
+ $totalsize += OC_Filesystem::filesize($dir.'/'.$file);
+ }
+ }else{
+ $totalsize += OC_Filesystem::filesize($dir.'/'.$files);
+ }
+ if($totalsize > $zipLimit) {
+ $l = new OC_L10N('files');
+ header("HTTP/1.0 409 Conflict");
+ $tmpl = new OC_Template( '', 'error', 'user' );
+ $errors = array(
+ array(
+ 'error' => $l->t('Selected files too large to generate zip file.'),
+ 'hint' => 'Download the files in smaller chunks, seperately or kindly ask your administrator.<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
+ )
+ );
+ $tmpl->assign('errors', $errors);
+ $tmpl->printPage();
+ exit;
+ }
+ }
+ }
+
+ /**
* try to detect the mime type of a file
*
* @param string path
@@ -256,7 +298,7 @@ class OC_Files {
return false;
}
}
-
+
/**
* set the maximum upload size limit for apache hosts using .htaccess
* @param int size filesisze in bytes