ttf(字体)文件未使用 Codeigniter 3 上传

ttf (font) file not uploading with Codeigniter 3

我在将 ttf 文件上传到服务器的上传文件夹时遇到问题,我的代码使用 otf, eot, woff 格式,但不能使用 ttf。 我在 application/config/mimes.php

中添加了 mime 类型
'ttf'   =>  array('font/sfnt', 'font/truetype', 'font/ttf', 'application/x-font-truetype', 'application/x-font-ttf', 'application/octet-stream'),
'otf'   =>  array('application/vnd.oasis.opendocument.formula-template', 'application/vnd.ms-opentype'),
'woff'  =>  'font/woff',
'eot'   =>  'application/vnd.ms-fontobject',

这是我上传的class配置

$config['allowed_types'] = 'ttf|otf|eot|woff';

我已经一一检查了所有这些,但仍然无法正常工作,我们将不胜感激。谢谢

在 codeigniter 2 和 3 中,存在一些关于 mime 输入和允许的文件类型的多个错误...尝试另一种没有 codeigniter 上传库的上传方法或尝试

$config['allowed_types'] = '*';

也可以先检查允许的类型再上传

$uploaded_file_extention = 'ttf'; //fetch the file extention first...
$allowed_types = array('ttf', 'otf', 'woff', 'eot');

if( !in_array($uploaded_file_extention, $allowed_types) ) {
    //do not continue to upload...
} else {
    //continue to upload with $config['allowed_types'] = '*';
}

终于,我找到了解决方案,但我不知道这是 CodeIgniter 错误还是我的服务器限制我上传这些文件。此代码解决了我的问题

$mimetype = $_FILES['fontfile']['type'];
if(in_array($mimetype, array('font/sfnt', 'font/truetype', 'font/ttf', 'application/x-font-truetype', 'application/x-font-ttf', 'application/octet-stream'))) {
    return true;
} else {
    return false;
}

如果为真,您可以调用 CodeIgniter 上传函数:

$config['allowed_types'] = '*';

任何正在寻找 PHP 和 CodeIgniter 解决方案的人,这里是解决方案。

感谢@berk-kanburlar 的提示