XLS文件未在代码点火器中上传


xls file is not uploading in codeigniter?

我想上传csv文件和xls文件,我的代码在下面
给出'

        `$configUpload['upload_path'] = './user_status/';`
         $configUpload['allowed_types'] = 'XLS|text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext|text/plain|text/csv|csv|application/vnd.ms-excel';
         $configUpload['max_size'] = '5000';
         $this->load->library('upload', $configUpload);
         $this->upload->do_upload('input field name')`;

我的csv文件上传得很好,但是当我选择XLS文件时,Codeigniter显示错误"您尝试上传的文件类型是不允许的"。

print_r($_FILES) 的结果是

Array ( [user_status_csv] => Array ( [name] => VTRACK.XLS [type] => application/vnd.ms-excel [tmp_name] => C:'xampp'tmp'phpB2C4.tmp [error] => 0 [size] => 2627412 ) ) 

我有同样的问题。 我通过修改 XLS 的 MIME 来解决

'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),

array('application/excel', 'application/vnd.ms-excel', 'application/octet-stream'),

您也可以尝试 XLSX

 $configUpload['allowed_types'] = '**XLSX|**XLS|text/comma-separated-values|application/csv|application/excel|application/vnd.ms-excel|application/vnd.msexcel|text/anytext|text/plain|text/csv|csv|application/vnd.ms-excel';

您也可以像这样提供文件扩展名

 $configUpload['allowed_types'] = 'xls|xlsx|csv';

您可以尝试使用来自 simmilair 主题的求解。答案表明浏览器将 xls(x) 作为应用程序/zip 发送。

请参考本主题:上传带有代码点火器、MIME 类型错误的 xls 或 xlsx 文件

解决方案:

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

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

在 mimes.php 配置文件中设置 mime 类型。您可以在上传文件管理器中使用 data() 方法确定您的文件哑剧类型

请检查以下内容:

http://isaber.info/blog/2013/01/23/codeigniter-upload-files-not-work/

xls 或 xlsx,csv 问题与 mime 类型有关。

解决方案是:

if ( $this->upload->do_upload('filename') ){
       $img = $this->upload->data();
       $ext = $img['file_ext'];                            
       $post['xlfile'] = time().$ext;
} else {
       var_dump($this->upload->data());
       exit();                            
       redirect('hr/hr/dashboard/');
}

如果 excel 文件上传失败,则在 else 条件下写入

var_dump($this->上传->数据()); 因此,将确定哑剧的类型。按索引名称file_type复制输出数组。

'file_type' => 字符串 'application/vnd.ms-office' (length=25)

然后在应用程序/配置/文件夹中打开 mimes.php。

搜索 xls、xlsx 并为数组添加以下 mime 类型。

它最多涵盖所有哑剧类型。

'xls' =>       array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/x-zip', 'application/vnd.ms-excel', 'application/msexcel','application/excel','application/vnd.ms-office'),

这将像魅力一样工作。