Skip to content

Commit 4d85f44

Browse files
authored
Merge pull request #49372 from nextcloud/feat/php-setup-file-upload
2 parents a2590a4 + 4a88848 commit 4d85f44

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',
116116
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
117117
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
118+
'OCA\\Settings\\SetupChecks\\PhpMaxFileSize' => $baseDir . '/../lib/SetupChecks/PhpMaxFileSize.php',
118119
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php',
119120
'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php',
120121
'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => $baseDir . '/../lib/SetupChecks/PhpOpcacheSetup.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ComposerStaticInitSettings
130130
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',
131131
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
132132
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
133+
'OCA\\Settings\\SetupChecks\\PhpMaxFileSize' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMaxFileSize.php',
133134
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php',
134135
'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php',
135136
'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOpcacheSetup.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
5959
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
6060
use OCA\Settings\SetupChecks\PhpGetEnv;
61+
use OCA\Settings\SetupChecks\PhpMaxFileSize;
6162
use OCA\Settings\SetupChecks\PhpMemoryLimit;
6263
use OCA\Settings\SetupChecks\PhpModules;
6364
use OCA\Settings\SetupChecks\PhpOpcacheSetup;
@@ -203,6 +204,7 @@ public function register(IRegistrationContext $context): void {
203204
$context->registerSetupCheck(PhpFreetypeSupport::class);
204205
$context->registerSetupCheck(PhpApcuConfig::class);
205206
$context->registerSetupCheck(PhpGetEnv::class);
207+
$context->registerSetupCheck(PhpMaxFileSize::class);
206208
$context->registerSetupCheck(PhpMemoryLimit::class);
207209
$context->registerSetupCheck(PhpModules::class);
208210
$context->registerSetupCheck(PhpOpcacheSetup::class);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Settings\SetupChecks;
11+
12+
use bantu\IniGetWrapper\IniGetWrapper;
13+
use OCP\IL10N;
14+
use OCP\IURLGenerator;
15+
use OCP\SetupCheck\ISetupCheck;
16+
use OCP\SetupCheck\SetupResult;
17+
use OCP\Util;
18+
19+
class PhpMaxFileSize implements ISetupCheck {
20+
public function __construct(
21+
private IL10N $l10n,
22+
private IURLGenerator $urlGenerator,
23+
private IniGetWrapper $iniGetWrapper,
24+
) {
25+
}
26+
27+
public function getCategory(): string {
28+
return 'php';
29+
}
30+
31+
public function getName(): string {
32+
return $this->l10n->t('PHP file size upload limit');
33+
}
34+
35+
public function run(): SetupResult {
36+
$upload_max_filesize = Util::computerFileSize((string)$this->iniGetWrapper->getString('upload_max_filesize'));
37+
$post_max_size = Util::computerFileSize((string)$this->iniGetWrapper->getString('post_max_size'));
38+
$max_input_time = (int)$this->iniGetWrapper->getString('max_input_time');
39+
$max_execution_time = (int)$this->iniGetWrapper->getString('max_execution_time');
40+
41+
$warnings = [];
42+
$recommendedSize = 16 * 1024 * 1024 * 1024;
43+
$recommendedTime = 3600;
44+
45+
// Check if the PHP upload limit is too low
46+
if ($upload_max_filesize < $recommendedSize) {
47+
$warnings[] = $this->l10n->t('The PHP upload_max_filesize is too low. A size of at least %1$s is recommended. Current value: %2$s.', [
48+
Util::humanFileSize($recommendedSize),
49+
Util::humanFileSize($upload_max_filesize),
50+
]);
51+
}
52+
if ($post_max_size < $recommendedSize) {
53+
$warnings[] = $this->l10n->t('The PHP post_max_size is too low. A size of at least %1$s is recommended. Current value: %2$s.', [
54+
Util::humanFileSize($recommendedSize),
55+
Util::humanFileSize($post_max_size),
56+
]);
57+
}
58+
59+
// Check if the PHP execution time is too low
60+
if ($max_input_time < $recommendedTime && $max_input_time !== -1) {
61+
$warnings[] = $this->l10n->t('The PHP max_input_time is too low. A time of at least %1$s is recommended. Current value: %2$s.', [
62+
$recommendedTime,
63+
$max_input_time,
64+
]);
65+
}
66+
67+
if ($max_execution_time < $recommendedTime && $max_execution_time !== -1) {
68+
$warnings[] = $this->l10n->t('The PHP max_execution_time is too low. A time of at least %1$s is recommended. Current value: %2$s.', [
69+
$recommendedTime,
70+
$max_execution_time,
71+
]);
72+
}
73+
74+
if (!empty($warnings)) {
75+
return SetupResult::warning(join(' ', $warnings), $this->urlGenerator->linkToDocs('admin-big-file-upload'));
76+
}
77+
78+
return SetupResult::success();
79+
}
80+
}

0 commit comments

Comments
 (0)