778   CodeIgniter PHP

CI上传文件时,发现Excel表格的xlsx格式不支持,死活上传不了!
查了文档才发现,文件上传的http请求中有个mimes限制。
在application/config下,有个mimes.php文件,



/*
| -------------------------------------------------------------------
| MIME TYPES
| -------------------------------------------------------------------
| This file contains an array of mime types.  It is used by the
| Upload class to help identify allowed file types.
|
*/
return array(
	'hqx'	=>	array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
	'cpt'	=>	'application/mac-compactpro',
	'csv'	=>	array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),

··········

)

说得非常清楚,这里列出了允许上传的文件类型。
大部分文件类型都包含了,就是没有xlsx,只好参照xls,添加进去,如下

return array(

······
	'xls'	=>	array('application/excel', 'application/vnd.ms-excel', 'application/msexcel','application/octet-stream','application/kset','application/vnd.ms-office','application/msword'),
	'xlsx'	=>	array('application/excel', 'application/vnd.ms-excel', 'application/msexcel','application/octet-stream','application/kset','application/vnd.ms-office','application/msword'),

···········
)



Leave a Reply

Your email address will not be published. Required fields are marked *