在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);`