解决nginx和php使用ckfinder无法上传大文件的问题

Posted reblue520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决nginx和php使用ckfinder无法上传大文件的问题相关的知识,希望对你有一定的参考价值。

现象描述:
cms内容发布系统上传不了大文件,当上传超过32M文件时就上传不了

提示:无效的文件. 文件尺寸太大。

分析文件上传过程:
browser --> nginx --> php

需要修改 nginx.conf和php.ini

1.nginx.conf新增如下参数,重启无效:
client_max_body_size 512M;
client_body_buffer_size 128M;


2.修改php.ini配置,重启php-fpm无效:
/usr/local/php-7.0.12_fpm/lib/php.ini

post_max_size = 512M
upload_max_filesize = 256M


3.找到上传文件代码所在的目录 /data/www/cms/cmsx.chinasoft.com.wx/httpdocs/public

直接通过关键字定位代码所在具体程序文件

[root@newcms:/data/www/cms/cmsx.chinasoft.com.wx/httpdocs/public]# grep -ri "无效的文件. 文件尺寸太大"
resources/js/libs/ckfinder/core/connector/php/lang/zh-cn.php: \'203\' => \'无效的文件. 文件尺寸太大。\',
resources/js/libs/ckfinder/lang/zh-cn.js: 203 : \'无效的文件. 文件尺寸太大。\',

发现使用了 ckfinder 这个富文本插件


经过搜索发现限制在配置文件config.php,修改最大文件问题解决:

[root@newcms:/data/www/cms/cmsx.chinasoft.com.wx/httpdocs/public]# find ./ -name config.php
/data/www/cms/cmsx.chinasoft.com.wx/httpdocs/public/resources/js/libs/ckfinder/config.php

$config[\'DefaultResourceTypes\'] = \'\';

$dir_name_1 = preg_replace(\'/.+\\/([^\\/]*[a-z]+\\.[a-z]+)\\/.+/\', \'$1\', $baseDir);
$config[\'ResourceType\'][] = Array(
\'name\' => $dir_name_1, // Single quotes not allowed
\'url\' => $baseUrl,
\'directory\' => $baseDir,
\'maxSize\' => "300M", # 修改此处
\'allowedExtensions\' => isset( $_GET[\'show_format\'] ) ? $_GET[\'show_format\'] : \'\',
\'deniedExtensions\' => \'\');

$config[\'AccessControl\'][] = Array(
\'role\' => \'*\',
\'resourceType\' => $dir_name_1,
\'folder\' => \'/\',

\'folderView\' => true,
\'folderCreate\' => true,
\'folderRename\' => false,
\'folderDelete\' => true,

\'fileView\' => true,
\'fileUpload\' => true,
\'fileRename\' => true,
\'fileDelete\' => true);


$dir_name_2 = \'All files list\';
$config[\'ResourceType\'][] = Array(
\'name\' => $dir_name_2,
\'url\' => \'\',
\'directory\' => \'\',
\'maxSize\' => "300M", # 修改此处
\'allowedExtensions\' => isset( $_GET[\'show_format\'] ) ? $_GET[\'show_format\'] : \'\',
\'deniedExtensions\' => \'\');

以上是关于解决nginx和php使用ckfinder无法上传大文件的问题的主要内容,如果未能解决你的问题,请参考以下文章

CKeditor+CKfinder无法上传带中文的照片

关于ckfinder上传文件添加自定义处理方案

Ckfinder上传图像但无法插入编辑器中

CKEditor + CKFinder (上传图片出现问题)

CKEditor+CKFinder,上传图片成功,图片链接正确,但是无法显示,请问怎么回事?

PHP ckeditor富文本编辑器 结合ckfinder实现图片上传功能