make upload size settings work probably. do not replace whole .htaccess, only replace what is needed. Consistent, human readable input on admin settings page.

This commit is contained in:
Arthur Schiwon 2012-04-13 10:43:19 +02:00
parent 1d8fdf52d5
commit 1bd27891e2
2 changed files with 42 additions and 12 deletions

View File

@ -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" );

View File

@ -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;
}
/**