问题描述
如果我上传 csv
文件,则 localhost
上没有问题,并且一切正常,但是当我在实时服务器上上传我的应用程序并上传csv
文件,然后抛出此错误:您尝试上传的文件类型是不允许的.
对于这种情况的发生,我感到困惑.请帮我解决这个问题.
If I upload a csv
file, there is no problem on localhost
and everything works fine, but when I upload my app on live server and upload a csv
file then this error thrown: The filetype you are attempting to upload is not allowed.
I am confused as to why this happens. Please help me to solve this.
对于我的 localhost
环境,我正在使用XAMPP和CodeIgniter.
For my localhost
environment, I am using XAMPP and CodeIgniter.
我只想允许上传 csv
个文件.
I only want to allow csv
file uploads.
推荐答案
检查2件事:
首先:在您的上传控制器中:请确保设置正确的允许类型
First:in your upload controller: make sure to set the correct allowed types
$config['allowed_types'] = 'csv';
$this->load->library('upload', $config);
第二:在您的config/mimes.php中更新数组 $ mimes
:
Second:update the array $mimes
in your config/mimes.php:
'csv' => array('application/vnd.ms-excel',
'text/anytext',
'text/plain',
'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')
更新:
您可以在上传控制器中使用 print_r($ _ FILES)
来检查是否缺少mime类型.这将输出如下内容:
you could use print_r($_FILES)
in your upload controller to check for the mime-type missing. this would output something like:
[userfile] => Array
(
[name] => teste1.csv
[type] => application/vnd.ms-excel
[tmp_name] => C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\binaries\tmp\php8BFD.tmp
[error] => 0
[size] => 7880
)
这篇关于Codeigniter错误:不允许您尝试上传的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!