使用codeigniter上传xls或xlsx文件,mime类型错误 [英] Upload xls or xlsx files with codeigniter, mime-type error

查看:545
本文介绍了使用codeigniter上传xls或xlsx文件,mime类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我相信这不是Codeigniter的问题本身,因为它更像是一个

Well, i believe this is not a Codeigniter problem per se as it is more of a mime-type.

我试图上传一个文件,一个xls(或xlsx)文件和mime类型的浏览器和php报告是应用程序/八位字节流,而不是应用程序/ excel application / vnd.ms-excel application / msexcel 。当然,codeigniter上传插件会报告一个错误(无效的文件类型),因为它试图匹配文件扩展名与mime类型。

I'm trying to upload a file, a xls (or xlsx) file and the mime-type the browser and the php report is application/octet-stream instead of application/excel, application/vnd.ms-excel or application/msexcel for a xls file. Of course codeigniter upload plugin will report an error (invalid file type) as it tries to match the file extension with the mime-type.

相同的代码工作了几个月,现在停止使用最新的Chrome(16.0.912.77),Firefox(10.0)和IE9。

The weird(est) thing might be that the same code worked for months and now stopped working with the latest Chrome (16.0.912.77), Firefox (10.0) and IE9.

任何人都有相同(或相似)的问题,并且关心分享解决方案吗?

Has anyone had the same (or similar) problem and care to share the solution?

非常感谢。
PS:我不会提供代码,因为它不是一个真正的代码,但如果必要,我会上传一些片段。

Thank you very much. PS: I won't provide code as it's not really a code matter, but if necessary i'll upload some snippets.

EDIT

这可能是相关的:在类似配置的相同浏览器不会发生错误,但使用MS Office而不是Libre Office(在我的电脑) 。它不会发生在基于GNU / Linux的+ Libre Office系统上。 SO,是不是可以在开源套件上运行Windows,或者Libre Office只是为了改变mime类型呢?

It might be relevant: the error doesn't happen with same browsers on a similar configuration, but with MS Office instead of Libre Office (on my pc). It doesn't happen on a GNU/Linux based + Libre Office system either. SO, could it be Windows playin' hard on the open source suite, or the Libre Office changing the mime-types just for the heck of it?

推荐答案

我也得到这个错误。

CI报告'application / zip'的文件类型,这是有意义的xlsx格式是压缩格式(重命名为zip并可以打开内容)。

CI is reporting a file type of 'application/zip' which makes sense as the xlsx format is a compressed format (rename it to zip and you can open the contents).

我已经添加/替换了以下行到mime类型文件(application / config / mimes。 php):

I have added/replaced the following line to the mime types file (application/config/mimes.php):

'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/zip'),

并且工作(至少为这个浏览器!)

and that works (for this browser at least!)

这篇关于使用codeigniter上传xls或xlsx文件,mime类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆