PhpMaxFileSize.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use bantu\IniGetWrapper\IniGetWrapper;
  9. use OCP\IL10N;
  10. use OCP\IURLGenerator;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. use OCP\Util;
  14. class PhpMaxFileSize implements ISetupCheck {
  15. public function __construct(
  16. private IL10N $l10n,
  17. private IURLGenerator $urlGenerator,
  18. private IniGetWrapper $iniGetWrapper,
  19. ) {
  20. }
  21. public function getCategory(): string {
  22. return 'php';
  23. }
  24. public function getName(): string {
  25. return $this->l10n->t('PHP file size upload limit');
  26. }
  27. public function run(): SetupResult {
  28. $upload_max_filesize = (string)$this->iniGetWrapper->getString('upload_max_filesize');
  29. $post_max_size = (string)$this->iniGetWrapper->getString('post_max_size');
  30. $max_input_time = (int)$this->iniGetWrapper->getString('max_input_time');
  31. $max_execution_time = (int)$this->iniGetWrapper->getString('max_execution_time');
  32. $warnings = [];
  33. $recommendedSize = 16 * 1024 * 1024 * 1024;
  34. $recommendedTime = 3600;
  35. // Check if the PHP upload limit is too low
  36. if (Util::computerFileSize($upload_max_filesize) < $recommendedSize) {
  37. $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.', [
  38. Util::humanFileSize($recommendedSize),
  39. $upload_max_filesize,
  40. ]);
  41. }
  42. if (Util::computerFileSize($post_max_size) < $recommendedSize) {
  43. $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.', [
  44. Util::humanFileSize($recommendedSize),
  45. $post_max_size,
  46. ]);
  47. }
  48. // Check if the PHP execution time is too low
  49. if ($max_input_time < $recommendedTime && $max_input_time !== -1) {
  50. $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.', [
  51. $recommendedTime,
  52. $max_input_time,
  53. ]);
  54. }
  55. if ($max_execution_time < $recommendedTime && $max_execution_time !== -1) {
  56. $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.', [
  57. $recommendedTime,
  58. $max_execution_time,
  59. ]);
  60. }
  61. if (!empty($warnings)) {
  62. return SetupResult::warning(join(' ', $warnings), $this->urlGenerator->linkToDocs('admin-big-file-upload'));
  63. }
  64. return SetupResult::success();
  65. }
  66. }