将csv上传到Codeigniter [英] Uploading a csv into Codeigniter
本文介绍了将csv上传到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
你会见到另一个。
这篇关于将csv上传到Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文