问题
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?
回答1:
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
回答2:
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';
来源:https://stackoverflow.com/questions/15388366/codeigniters-file-upload-library-ignores-allowed-types