]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make max upload filesize configurable for apache hosts
authorRobin Appelman <icewind1991@gmail.com>
Sun, 29 May 2011 15:43:13 +0000 (17:43 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 29 May 2011 15:43:13 +0000 (17:43 +0200)
files/admin.php
files/settings.php
files/templates/admin.php
lib/files.php
lib/setup.php

index 0333e2c6cb1c2bde02c10d32660e300cf6e89152..59b822468ed44a2343fd90fa4806759e30c0fad6 100644 (file)
 require_once('../lib/base.php');
 require( 'template.php' );
 
+
 // Check if we are a user
 if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
        header( "Location: ".OC_HELPER::linkTo( "index.php" ));
        exit();
 }
 
+$htaccessWorking=(getenv('htaccessWorking')=='true');
+if(isset($_POST['maxUploadSize'])){
+       $maxUploadFilesize=$_POST['maxUploadSize'];
+       OC_FILES::setUploadLimit(OC_HELPER::computerFileSize($maxUploadFilesize));
+}else{
+       $maxUploadFilesize = ini_get('upload_max_filesize').'B';
+}
+
 OC_APP::setActiveNavigationEntry( "files_administration" );
 // return template
 $tmpl = new OC_TEMPLATE( "files", "admin", "admin" );
+$tmpl->assign( 'htaccessWorking', $htaccessWorking );
+$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
 $tmpl->printPage();
 
 ?>
index 6d237ed615236ae56843f699f7fad2f7c42e56a2..23aed4d1b866a0727b4530cc5e011b048b184486 100644 (file)
@@ -57,7 +57,7 @@ foreach( explode( "/", $dir ) as $i ){
 
 // return template
 $tmpl = new OC_TEMPLATE( "files", "index", "user" );
-$tmpl->assign( "files", $files );
+$tmpl->assign( 'files', $files );
 $tmpl->assign( "breadcrumb", $breadcrumb );
 $tmpl->printPage();
 
index 65a540ac914a06a59245936742a1c2a2ab14bb2d..f768931eb2f95895e113c5efd26d31b290aeeada 100644 (file)
@@ -1,4 +1,7 @@
-<form>
+<form action='#' method='post'>
+       <?php if($_['htaccessWorking']):?>
+               Maximum upload size <input name='maxUploadSize' value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/>
+       <?php endif;?>
        <input type="checkbox" /> Allow public folders<br>
 
        (if public is enabled)<br>
@@ -9,4 +12,5 @@
 
        <input type="checkbox" /> Allow downloading shared files<br>
        <input type="checkbox" /> Allow uploading in shared directory<br>
+       <input type='submit' value='Save'/>
 </form>
index 2a56c5b4b37b5731daeef27656abd2c360eb405b..9e66f9dab827a985fec04d34ac48a2df087ccd36 100644 (file)
@@ -291,6 +291,24 @@ class OC_FILES {
                        return false;
                }
        }
+       
+       /**
+        * set the maximum upload size limit for apache hosts using .htaccess
+        * @param int size filesisze in bytes
+        */
+       static function setUploadLimit($size){
+               global $SERVERROOT;
+               global $WEBROOT;
+               $size=OC_HELPER::humanFileSize($size);
+               echo $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 /$WEBROOT/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";
+               @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
+       }
 }
 
 function zipAddDir($dir,$zip,$internalDir=''){
index fa0b8f85905e2a82131e86d7c5b81a8985b3c746..72507f221b9f0ecf5f8bf6fe4f2e9b8ff0e8b2b8 100644 (file)
@@ -167,7 +167,10 @@ class OC_SETUP {
        private static function createHtaccess() {
                global $SERVERROOT;
                global $WEBROOT;
-               $content = "ErrorDocument 404 /$WEBROOT/templates/404.php\n";
+               $content = "ErrorDocument 404 /$WEBROOT/templates/404.php\n";//custom 404 error page
+               $content.= "php_value upload_max_filesize 20M\n";//upload limit
+               $content.= "php_value post_max_size 20M\n";
+               $content.= "SetEnv htaccessWorking true\n";
                @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
 
                $content = "deny from all";