Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

php - Upload xls or xlsx files with codeigniter, mime-type error

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

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.

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?

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm getting this error also.

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).

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!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...