【问题标题】:php.ini max_upload_file size falling back to default 2Mphp.ini max_upload_file 大小回退到默认 2M
【发布时间】:2016-12-07 10:19:51
【问题描述】:

我必须使用“备份和迁移”模块在 drupal-7 中上传 5.7MB 的数据库。但是,当我上传文件时,它会抛出以下错误:

The file email839805758.zip could not be saved, because it exceeds 2 MB, the maximum allowed size for uploads.

我在 php.ini 文件中更改了 post_max_size = 20M 和 upload_max_filesize = 40M 并在 /etc/php/5.6/apache2/conf.d/user.ini 中创建了 user.ini。并粘贴 post_max_size 和 upload_max_filesize 大于 2M。我已经检查了 phpinfo()。它只是将默认值设置为 2M。有人对drupal 7中的这种场景有任何解决方案吗?

我在 drupal backup_migrate.module 文件中发现了一些额外的东西,这可能是障碍。帮我破解这个功能。

  /**
  * A custom version of format size which treats 1GB as 1000 MB rather than 1024 MB
  * This is a more standard and expected version for storage (as opposed to memory).
  */
  function backup_migrate_format_size($size, $langcode = LANGUAGE_NONE)    {
  $precision = 2;
  $multiply = pow(10, $precision);

  if ($size == 0) {
  return t('0 bytes', array(), array('langcode' => $langcode));
   }
  if ($size < 1024) {
  return format_plural($size, '1 byte', '@count bytes', array(),   array('langcode' => $langcode));
  }
  else {
  $size = ceil($size * $multiply / 1024);
  $string = '@size KB';
  if ($size >= (1024 * $multiply)) {
  $size = ceil($size / 1024);
  $string = '@size MB';
  }
  if ($size >= 1000 * $multiply) {
  $size = ceil($size / 1000);
  $string = '@size GB';
  }
  if ($size >= 1000 * $multiply) {
  $size = ceil($size / 1000);
  $string = '@size TB';
  }
   return t($string, array('@size' => round($size/$multiply, $precision)), array('langcode' => $langcode));
  }

  }

【问题讨论】:

  • 也许它是由ini_set() 设置的代码?找到这个地方或在表单的处理程序中添加ini_set('post_max_size', '20M')
  • ini_set() 在哪里,我在 php.ini 中找不到
  • 在您的应用程序代码中查看它,如果您使用 PhpStorm,请按 CTRL + Shitf + F
  • 第二种变体更受欢迎,因为您不需要在所有表单中上传这种大小的文件
  • 在 php.ini 上搜索 post_max_size 并将其增加到您想要的大小。不要忘记重新启动服务器

标签: php mysql apache drupal drupal-7


【解决方案1】:

在你的脚本中输入 phpinfo() 并查看你使用的是哪个 php.ini 文件。进入该文件并更改这些值。请记住,必须重新启动守护程序(php-fpm 或 apache)才能激活更改。

如果由于某种原因你不能这样做,你总是可以在本地使用 ini_set() 函数,但强烈建议不要这样做!

【讨论】:

    【解决方案2】:

    使用 phpinfo() 检查使用的 php 配置文件。对我来说,您似乎编辑了错误的 php.ini。另外,不要忘记重新启动您的网络服务器(Apache?)。

    【讨论】:

      猜你喜欢
      • 2018-02-01
      • 1970-01-01
      • 2018-06-07
      • 2020-04-04
      • 2021-10-30
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多