Update .user.ini when setting upload size limit
This commit is contained in:
parent
f573659b3a
commit
d3bcafe618
|
@ -42,9 +42,10 @@ if($_POST && OC_Util::isCallRegistered()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$htaccessWritable=is_writable(OC::$SERVERROOT.'/.htaccess');
|
$htaccessWritable=is_writable(OC::$SERVERROOT.'/.htaccess');
|
||||||
|
$userIniWritable=is_writable(OC::$SERVERROOT.'/.user.ini');
|
||||||
|
|
||||||
$tmpl = new OCP\Template( 'files', 'admin' );
|
$tmpl = new OCP\Template( 'files', 'admin' );
|
||||||
$tmpl->assign( 'uploadChangable', $htaccessWorking and $htaccessWritable );
|
$tmpl->assign( 'uploadChangable', ($htaccessWorking and $htaccessWritable) or $userIniWritable );
|
||||||
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
|
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
|
||||||
// max possible makes only sense on a 32 bit system
|
// max possible makes only sense on a 32 bit system
|
||||||
$tmpl->assign( 'displayMaxPossibleUploadSize', PHP_INT_SIZE===4);
|
$tmpl->assign( 'displayMaxPossibleUploadSize', PHP_INT_SIZE===4);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
<br/>
|
<br/>
|
||||||
<input type="hidden" value="<?php p($_['requesttoken']); ?>" name="requesttoken" />
|
<input type="hidden" value="<?php p($_['requesttoken']); ?>" name="requesttoken" />
|
||||||
<?php if($_['uploadChangable']): ?>
|
<?php if($_['uploadChangable']): ?>
|
||||||
|
<?php p($l->t('With PHP-FPM this value may take up to 5 minutes to take effect after saving.')); ?>
|
||||||
|
<br/>
|
||||||
<input type="submit" name="submitFilesAdminSettings" id="submitFilesAdminSettings"
|
<input type="submit" name="submitFilesAdminSettings" id="submitFilesAdminSettings"
|
||||||
value="<?php p($l->t( 'Save' )); ?>"/>
|
value="<?php p($l->t( 'Save' )); ?>"/>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||||
* @author Valerio Ponte <valerio.ponte@gmail.com>
|
* @author Valerio Ponte <valerio.ponte@gmail.com>
|
||||||
* @author Vincent Petry <pvince81@owncloud.com>
|
* @author Vincent Petry <pvince81@owncloud.com>
|
||||||
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||||
* @license AGPL-3.0
|
* @license AGPL-3.0
|
||||||
|
@ -288,38 +289,63 @@ class OC_Files {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//suppress errors in case we don't have permissions for
|
|
||||||
$htaccess = @file_get_contents(OC::$SERVERROOT . '/.htaccess');
|
|
||||||
if (!$htaccess) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$phpValueKeys = array(
|
$phpValueKeys = array(
|
||||||
'upload_max_filesize',
|
'upload_max_filesize',
|
||||||
'post_max_size'
|
'post_max_size'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$updateFiles = [
|
||||||
|
OC::$SERVERROOT . '/.htaccess' => [
|
||||||
|
'pattern' => '/php_value %1$s (\S)*/',
|
||||||
|
'setting' => 'php_value %1$s %2$s'
|
||||||
|
],
|
||||||
|
OC::$SERVERROOT . '/.user.ini' => [
|
||||||
|
'pattern' => '/%1$s=(\S)*/',
|
||||||
|
'setting' => '%1$s=%2$s'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$success = true;
|
||||||
|
|
||||||
|
foreach ($updateFiles as $filename => $patternMap) {
|
||||||
|
// suppress warnings from fopen()
|
||||||
|
$handle = @fopen($filename, 'r+');
|
||||||
|
if (!$handle) {
|
||||||
|
\OCP\Util::writeLog('files',
|
||||||
|
'Can\'t write upload limit to ' . $filename . '. Please check the file permissions',
|
||||||
|
\OCP\Util::WARN);
|
||||||
|
$success = false;
|
||||||
|
continue; // try to update as many files as possible
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = '';
|
||||||
|
while (!feof($handle)) {
|
||||||
|
$content .= fread($handle, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($phpValueKeys as $key) {
|
foreach ($phpValueKeys as $key) {
|
||||||
$pattern = '/php_value ' . $key . ' (\S)*/';
|
$pattern = vsprintf($patternMap['pattern'], [$key]);
|
||||||
$setting = 'php_value ' . $key . ' ' . $size;
|
$setting = vsprintf($patternMap['setting'], [$key, $size]);
|
||||||
$hasReplaced = 0;
|
$hasReplaced = 0;
|
||||||
$content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
|
$newContent = preg_replace($pattern, $setting, $content, 1, $hasReplaced);
|
||||||
if ($content !== null) {
|
if ($newContent !== null) {
|
||||||
$htaccess = $content;
|
$content = $newContent;
|
||||||
}
|
}
|
||||||
if ($hasReplaced === 0) {
|
if ($hasReplaced === 0) {
|
||||||
$htaccess .= "\n" . $setting;
|
$content .= "\n" . $setting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for write permissions
|
// write file back
|
||||||
if (is_writable(OC::$SERVERROOT . '/.htaccess')) {
|
ftruncate($handle, 0);
|
||||||
file_put_contents(OC::$SERVERROOT . '/.htaccess', $htaccess);
|
rewind($handle);
|
||||||
|
fwrite($handle, $content);
|
||||||
|
|
||||||
|
fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($success) {
|
||||||
return OC_Helper::computerFileSize($size);
|
return OC_Helper::computerFileSize($size);
|
||||||
} else {
|
|
||||||
\OCP\Util::writeLog('files',
|
|
||||||
'Can\'t write upload limit to ' . OC::$SERVERROOT . '/.htaccess. Please check the file permissions',
|
|
||||||
\OCP\Util::WARN);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue