【发布时间】: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