diff --git a/files/admin.php b/files/admin.php index ea846202ab..7e410652cf 100644 --- a/files/admin.php +++ b/files/admin.php @@ -28,13 +28,20 @@ require_once('../lib/base.php'); OC_Util::checkAdminUser(); $htaccessWorking=(getenv('htaccessWorking')=='true'); -if(isset($_POST['maxUploadSize'])){ - $maxUploadFilesize=$_POST['maxUploadSize']; - OC_Files::setUploadLimit(OC_Helper::computerFileSize($maxUploadFilesize)); +if($_POST) { + if(isset($_POST['maxUploadSize'])){ + $maxUploadFilesize=$_POST['maxUploadSize']; + OC_Files::setUploadLimit(OC_Helper::computerFileSize($maxUploadFilesize)); + } + if(isset($_POST['maxZipInputSize'])) { + $maxZipInputSize=$_POST['maxZipInputSize']; + OC_Preferences::setValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize($maxZipInputSize)); + } }else{ $upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); + $maxZipInputSize = OC_Helper::humanfilesize(OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'))); } OC_App::setActiveNavigationEntry( "files_administration" ); @@ -42,6 +49,5 @@ OC_App::setActiveNavigationEntry( "files_administration" ); $tmpl = new OC_Template( 'files', 'admin' ); $tmpl->assign( 'htaccessWorking', $htaccessWorking ); $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize); -return $tmpl->fetchPage(); - -?> +$tmpl->assign( 'maxZipInputSize', $maxZipInputSize); +return $tmpl->fetchPage(); \ No newline at end of file diff --git a/files/templates/admin.php b/files/templates/admin.php index eb65544704..8c3ba56ad5 100644 --- a/files/templates/admin.php +++ b/files/templates/admin.php @@ -3,11 +3,10 @@
t('File handling');?> - - '/>
- - - No settings currently available. - + + '/>
+ + '/>
+
diff --git a/lib/files.php b/lib/files.php index 1f8331afb2..50223df1d3 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; @@ -209,6 +217,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.
' . $l->t('Back to Files') . '', + ) + ); + $tmpl->assign('errors', $errors); + $tmpl->printPage(); + exit; + } + } + } + /** * try to detect the mime type of a file * @@ -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