在codeigniter中上传pdf,csv和其他文件类型 [英] upload pdf, csv and other file type in codeigniter

查看:55
本文介绍了在codeigniter中上传pdf,csv和其他文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码以上传csv,pdf和其他

code to upload csv, pdf and other

$config['allowed_types'] = "application/pdf|pdf|application/octet-stream|csv";

print_r($_FILES);

给予对于csv

Array ( [userfile] => Array ( [name] => file.csv [type] => application/octet-stream [tmp_name] => C:\xampp\tmp\php4FD2.tmp [error] => 0 [size] => 7 ) )

对于pdf

Array ( [userfile] => Array ( [name] => doc.pdf [type] => application/pdf [tmp_name] => C:\xampp\tmp\phpA4E5.tmp [error] => 0 [size] => 127670 ) ) 

$this->upload->display_errors()

同时给予

Array ( [error] => 1 [msg] => The filetype you are attempting to upload is not allowed. )

任何人都想念水是问题

我也尝试过其他类似的方法在mimes.php中

i also tried ans from other que like this in mimes.php

'pdf'   =>      array('application/pdf', 'application/x-pdf', 'application/x-download','application/x-download', 'binary/octet-stream', 'application/unknown', 'application/force-download'),

推荐答案

请在您的application \ config \ mimes.php文件中添加它.

please add this in your application\config\mimes.php file.

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

'pdf'   =>  array('application/pdf', 'application/x-download')

现在可以在控制器中使用上传功能

now on upload function in controller use

$config['allowed_types'] = 'pdf|csv';

$this->load->library('upload', $config);

$this->upload->initialize($config);`

这篇关于在codeigniter中上传pdf,csv和其他文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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