Search code examples
phpcodeignitermime-typestruetype

ttf (font) file not uploading with Codeigniter 3


I'm having a problem uploading ttf file to the server's upload folder, my code is working with otf, eot, woff formats, but not working with ttf. I've added the mime type in application/config/mimes.php

'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',

This is my upload class config

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

I've checked all these one by one and together, but still not working, any help will be appreciated. thanks


Solution

  • In codeigniter 2 and 3 there are some multiple bugs about mime typing and allowed file types... Try another upload method without codeigniter upload library or try

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

    also you can check allowed types first then upload it

    $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'] = '*';
    }