将 csv 上传到 Codeigniter [英] Uploading a csv into Codeigniter
问题描述
有没有其他人在将 csv 文件上传到 Codeigniter 时遇到问题?我收到一个非常烦人的不允许您尝试上传的文件类型".错误,即使我已经非常明确地设置了上传类型.这是我的代码(应该是相当标准的东西):
Has anyone else had trouble uploading a csv file into Codeigniter? I'm getting a pretty annoying "The filetype you are attempting to upload is not allowed." error, even though I've quite explicitly set the upload type. Here's my code (should be fairly standard stuff):
function doUpload() {
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'text/plain|text/csv|csv';
$config['max_size'] = '5000';
$config['file_name'] = 'upload' . time();
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
$file_info = $this->upload->data();
$csvfilepath = "uploads/" . $file_info['file_name'];
$this->addfromcsv($csvfilepath);
}
}
我试图涵盖我允许的类型中的所有基础 - 也许我错过了一个?感谢您对此的任何帮助!
I tried to cover all the bases in my allowed types - maybe I missed one? Thanks for any help with this!
推荐答案
不幸的是没有官方规范,所以有很多:缺少的那些中最受欢迎的是,
Unluckily there is no official specification, so there's quite a lot of them: the most popular among those that are missing are,
text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext
你极不可能遇到另一个人.
It's highly unlikely you'll meet another one.
这篇关于将 csv 上传到 Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!