douzi8127 2015-03-20 13:18
浏览 75
已采纳

Codeigniter错误:不允许您尝试上传的文件类型

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.

For my localhost environment, I am using XAMPP and CodeIgniter.

I only want to allow csv file uploads.

  • 写回答

2条回答 默认 最新

  • dounang1974 2015-03-23 21:56
    关注

    check 2 things:

    First: in your upload controller: make sure to set the correct allowed types

    $config['allowed_types'] = 'csv';
    $this->load->library('upload', $config);
    

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

    UPDATE:

    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
        )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效