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

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

问题描述

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

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

我正在尝试上传一个文件、一个 xls(或 xlsx)文件和浏览器的 MIME 类型,并且 php 报告是 application/octet-stream 而不是 application/excelapplication/vnd.ms-excelapplication/msexcel 用于 xls 文件.当然,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.

编辑

这可能是相关的:错误不会发生在类似配置的相同浏览器上,而是使用 MS Office 而不是 Libre Office(在我的电脑上).它也不会发生在基于 GNU/Linux 的 + Libre Office 系统上.那么,是 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 报告的文件类型为应用程序/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、mime 类型错误的 xls 或 xlsx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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