diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2012-04-13 10:43:19 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2012-04-13 10:43:44 +0200 |
commit | 1bd27891e2d0f62f4ab9588dec9ca12b79e50030 (patch) | |
tree | 7a1dff4be437e60fa270a5953756e6f1ec2468ba | |
parent | 1d8fdf52d52f4a73cb0a59b5d2c3a088ae1e9247 (diff) | |
download | nextcloud-server-1bd27891e2d0f62f4ab9588dec9ca12b79e50030.tar.gz nextcloud-server-1bd27891e2d0f62f4ab9588dec9ca12b79e50030.zip |
make upload size settings work probably. do not replace whole .htaccess, only replace what is needed. Consistent, human readable input on admin settings page.
-rw-r--r-- | files/admin.php | 13 | ||||
-rw-r--r-- | lib/files.php | 41 |
2 files changed, 42 insertions, 12 deletions
diff --git a/files/admin.php b/files/admin.php index 289d95cb912..04ef6a4e828 100644 --- a/files/admin.php +++ b/files/admin.php @@ -29,10 +29,14 @@ OC_Util::checkAdminUser(); $htaccessWorking=(getenv('htaccessWorking')=='true'); +$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); +$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); +$maxUploadFilesize = OC_Helper::humanFileSize(min($upload_max_filesize, $post_max_size)); if($_POST) { if(isset($_POST['maxUploadSize'])){ - $maxUploadFilesize=$_POST['maxUploadSize']; - OC_Files::setUploadLimit(OC_Helper::computerFileSize($maxUploadFilesize)); + if(($setMaxSize = OC_Files::setUploadLimit(OC_Helper::computerFileSize($_POST['maxUploadSize']))) !== false) { + $maxUploadFilesize = OC_Helper::humanFileSize($setMaxSize); + } } if(isset($_POST['maxZipInputSize'])) { $maxZipInputSize=$_POST['maxZipInputSize']; @@ -42,10 +46,7 @@ if($_POST) { OC_Config::setValue('allowZipDownload', isset($_POST['allowZipDownload'])); } } -$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_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB'))); +$maxZipInputSize = OC_Helper::humanFileSize(OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB'))); $allowZipDownload = intval(OC_Config::getValue('allowZipDownload', true)); OC_App::setActiveNavigationEntry( "files_administration" ); diff --git a/lib/files.php b/lib/files.php index a68c29ad989..473be51fdd1 100644 --- a/lib/files.php +++ b/lib/files.php @@ -317,17 +317,46 @@ class OC_Files { /** * set the maximum upload size limit for apache hosts using .htaccess * @param int size filesisze in bytes + * @return mixed false on failure, size on success */ static function setUploadLimit($size){ $size=OC_Helper::humanFileSize($size); $size=substr($size,0,-1);//strip the B $size=str_replace(' ','',$size); //remove the space between the size and the postfix - $content = "ErrorDocument 404 /".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page - $content.= "php_value upload_max_filesize $size\n";//upload limit - $content.= "php_value post_max_size $size\n"; - $content.= "SetEnv htaccessWorking true\n"; - $content.= "Options -Indexes\n"; - @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it + + //don't allow user to break his config + if(intval($size) == 0) { + return false; + } + + $htaccess = @file_get_contents(OC::$SERVERROOT.'/.htaccess'); //supress errors in case we don't have permissions for + if(!$htaccess) { + return false; + } + + $phpValueKeys = array( + 'upload_max_filesize', + 'post_max_size' + ); + + foreach($phpValueKeys as $key) { + $pattern = '/php_value '.$key.' (\S)*/'; + $setting = 'php_value '.$key.' '.$size; + $hasReplaced = 0; + $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced); + if($content !== NULL) { + $htaccess = $content; + } + if($hasReplaced == 0) { + $htaccess .= "\n" . $setting; + } + } + + //supress errors in case we don't have permissions for it + if(@file_put_contents(OC::$SERVERROOT.'/.htaccess', $htaccess)) { + return OC_Helper::computerFileSize($size); + } + return false; } /** |