You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Contact Form7拖拽多文件上传插件时HTML文件上传报错‘文件类型不允许’

解决Contact Form7搭配Drag and Drop插件上传HTML文件报错的问题

针对你遇到的「Uploaded file is not allowed for file type」错误,可按以下步骤排查解决:

1. 解除WordPress默认的文件类型限制

WordPress默认禁止上传HTML、JS这类文件,需要手动添加允许规则。将以下代码添加到当前主题的functions.php文件中:

function allow_custom_file_types($mimes) {
    // 允许HTML、JS、CSS文件
    $mimes['html'] = 'text/html';
    $mimes['js'] = 'application/javascript';
    $mimes['css'] = 'text/css';
    return $mimes;
}
add_filter('upload_mimes', 'allow_custom_file_types');

2. 检查Drag and Drop插件的全局扩展名设置

进入插件的设置页面(一般在「Contact > Drag & Drop Upload」路径下),找到「Allowed File Extensions」选项,确认是否已经添加html、js、css这三个扩展名。如果没加,补充进去后保存设置。

3. 禁用「Enable to sanitize the multiple file extensions」选项

你当前启用了这个sanitize功能,它可能会对扩展名进行额外过滤,导致合法的HTML文件被误拦截。尝试关闭这个选项,然后重新测试上传。

4. 强制插件识别正确的MIME类型

如果上述步骤无效,可添加代码强制插件接受对应文件的MIME类型:

function dnd_allow_custom_mimes($allowed_mimes) {
    $allowed_mimes['html'] = 'text/html';
    $allowed_mimes['js'] = 'application/javascript';
    $allowed_mimes['css'] = 'text/css';
    return $allowed_mimes;
}
add_filter('dnd_upload_allowed_mimes', 'dnd_allow_custom_mimes');

按顺序尝试以上步骤,基本可以解决文件类型被拦截的问题。

内容的提问来源于stack exchange,提问作者Phan Duy Thành

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 10:08:13