Francois Bourgeois
Francois Bourgeois

Reputation: 3690

CodeIgniter's file upload library ignores allowed_types?

I tried to upload a certificate file and failed:

$config["allowed_types"] = "cer";
$this->load->library("upload", $config);
$this->upload->do_upload("fieldname");

I always get the following error, even if I upload a .cer file:

The filetype you are attempting to upload is not allowed

That is a lie, I uploaded a file of an allowed type! Why does this class ignore its documented setting allowed_types?

Upvotes: 0

Views: 3463

Answers (2)

Chibueze Opata
Chibueze Opata

Reputation: 10054

You need to add the mime type in mimes.php config file. It should be something like this:

'cer' => array('application/x-x509-ca-cert', 'application/octet-stream'),

Location of mime: application/config/mime.php

Upvotes: 1

RayZor
RayZor

Reputation: 665

I had a similar problem trying to upload csv's when they'd been generated by excel - in the end I had to use an extended list of mime types to allow the files to be uploaded. I've done a quick search for .cer mime-types and got two candidates, try using:

 $config['allowed_types']  = 'cer|application/x-x509-ca-cert|application/pkix-cert';

Upvotes: 0

Related Questions