我正在尝试上传一个css文件用户codigniter的上传类。这是控制器:
public function uploadcssfile()
{
$config['upload_path'] = './stylesheets/stores/'.$memberid.'/';
$config['file_name'] = 'main.css';
$config['allowed_types'] = 'css';
$config['overwrite'] = true;
$this->load->library('upload', $config);
if (! $this->upload->do_upload('filefieldname'))
{
die($this->upload->display_errors());
}
}
我只想上传一个css类型的文件,但codeigniter总是给出这样的错误:
The filetype you are attempting to upload is not allowed.
我知道,这真的很奇怪,但它对我有效:
在application/config/mimes.php中,第77行
'css' => 'text/css',
更改为:
'css' => array('text/css','text/x-c'),
要了解,如果您的开发环境有自己的幽默感,并且可以向任何文本文件添加新的mime类型(我的情况),请检查您的mime,如下所示:
if ( ! $this->upload->do_upload(-your-form-input-name-) ){
print_r($_FILES['-your-form-input-name-']['type']);
exit($this->upload->display_errors(). 'File Type: ' . $this->upload->file_type);
}
如果上传失败,它将向您显示服务器实际要处理的mime类型。
PS。既然你的问题已经有了答案,请点击此处帮助我:)