我经常搜索并发现很多关于这个问题的问题,遗憾的是没有一个答案对我有帮助.
The filetype you are attempting to upload is not allowed.
我正在遵循此CI指南来构建我的代码:http://codeigniter.com/user_guide/libraries/file_uploading.html
这是我得到的:
查看文件:
[..] <?= form_open_multipart() ?> <input type="file" name="userfile" size="20" /> <br /><br /> <input type="submit" value="upload" /> <?= form_close() ?> [..]
我的控制器:
$config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload',$config); $xx = array('upload_data' => $this->upload->data()); $mimetype= $xx['upload_data']['file_type']; var_dump('Mime: ' . $mimetype); var_dump($_FILES); if ( !$this->upload->do_upload()) { Notice::add($this->upload->display_errors(),'error'); } else { $data['upload_data'] = $this->upload->data(); }
正如你所看到的,我正在尝试var_dump mime类型,结果为空.
当我做var_dump($_ FILES)时,看起来一切都很好:
array(1) { ["userfile"]=> array(5) { ["name"]=> string(14) "imageofm.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(18) "/var/tmp/PHP5cDAZJ" ["error"]=> int(0) ["size"]=> int(358) } }
另外,我得到’png’=>数组(‘image / png’,’image / x-png’),line,在我的config / mimes.PHP中.
但是,它确实发生在所有图像上(还没有尝试过其他扩展).
我很感激每一次尝试.
只需编辑application / config / mimes.PHP中的mimes.PHP文件,并用以下内容替换csv的行:
原文链接:https://www.f2er.com/php/133232.html'csv' => array('application/vnd.ms-excel','text/anytext','text/plain','text/x-comma-separated-values','text/comma-separated-values','application/octet-stream','application/vnd.ms-excel','application/x-csv','text/x-csv','text/csv','application/csv','application/excel','application/vnd.msexcel')