CodeIgniter's file upload library ignores allowed_types?

佐手、 提交于 2019-12-25 01:26:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!