summaryrefslogtreecommitdiffstats
path: root/lib/files.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2012-04-13 10:43:19 +0200
committerArthur Schiwon <blizzz@owncloud.com>2012-04-13 10:43:44 +0200
commit1bd27891e2d0f62f4ab9588dec9ca12b79e50030 (patch)
tree7a1dff4be437e60fa270a5953756e6f1ec2468ba /lib/files.php
parent1d8fdf52d52f4a73cb0a59b5d2c3a088ae1e9247 (diff)
downloadnextcloud-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.
Diffstat (limited to 'lib/files.php')
-rw-r--r--lib/files.php41
1 files changed, 35 insertions, 6 deletions
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;
}
/**